LoginSignup
15
12

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-03-12

はじめに

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}

alg.png

15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12