[latex]IEEEtranでalgorithmパッケージの使い方


はじめに

IEEEにlatexで論文投稿する場合、IEEEtran.clsというクラスファイルを使います。
このクラスファイルのHOWTOには、アルゴリズムのfloating environmentとしてalgorithm.sty, algorithm2e.styを使うな、と書かれています。
では、どうすればいいのか、というとfigure environmentを使え、ということらしいです。

algorithm.styの使い方はググればいっぱい出てきますが、algorithm.styのfloating environmentを使わずにfigure environmentを使ってアルゴリズムを載せるコードがあまり見当たらないので、例を載せておきます。

方法としてはfigureの中にalgorithm環境を埋め込めばOKです。

参考

https://tex.stackexchange.com/questions/147598/
https://tex.stackexchange.com/questions/82271/

algorithmic.styとalgorithmicx.styはどちらを使っても良い。
以下の例はalgorithmicx.sty用

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}

% 中略

\begin{figure}[!t]
  \begin{algorithm}[H]
    \caption{Caption}
    \label{alg1}
    \begin{algorithmic}
      \Require args $x_i$
      \Ensure total $s$
      \State $s \leftarrow 0$
      \For{$i=1,\cdots,n$}
        \State $s \leftarrow s + x_i$
      \EndFor
      \State \Return $s$
    \end{algorithmic}
  \end{algorithm}
\end{figure}