[Tex/LaTex] Algorithm and IEEEtran


I'm trying to write an algorithm in a IEEEtran LaTeX template and it doesn't work in any way.


\caption{ASGP Merge and Pruning Step}
\REQUIRE {$stuff$}
\STATE $stuff$
\RETURN $stuff$

but this is what I get:

! LaTeX Error: \begin{ALC@g} on input line 31 ended by \end{algorithmic}.

See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.

l.47 \end{algorithmic}

I already tried use \begin{figure*} instead of \begin{algorithm*} but that
also doesn't work.

I saw a post about using \begin{algpseudocode}, but that isn't working either,
If I also \include{algorithmic}:

! LaTeX Error: Command \algorithmicindent already defined.
Or name \end… illegal, see p.192 of the manual.

If not, I get:

\REQUIRE undefined control sequence.

Can anybody help me with that?

Best Answer

The IEEEtran's documentation suggests:

B. Algorithms

IEEE publications use the figure environment to contain algorithms that are not to be a part of the main text flow. Peter Williams’ and Rogerio Brito’s algorithmic.sty package [24] or Szász János’ algorithmicx.sty package [25] (the latter is designed to be more customizable than the former) may be of help in producing algorithm-like structures (although authors are of course free to use whatever LaTeX commands they are most comfortable with in this regard). However, do not use the floating algorithm environment of algorithm.sty (also by Williams and Brito) or algorithm2e.sty (by Christophe Fiorio) as the only floating structures IEEE uses are figures and tables. Furthermore, IEEEtran will not be in control of the (non-IEEE) caption style produced by the algorithm.sty or algorithm2e.sty float environments.

So, as suggested, do not use the algorithm floating environment; you can wrap your algorithm inside a figure (or figure*) environment (if a caption is required and the captions are to be IEEEtran compliant) and use the algorithmicx package ; something like this:



\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\State \textbf{return} $b$\Comment{The gcd is b}
\caption{Euclid's algorithm}\label{euclid}


enter image description here

If no caption is required, then simply don't use the figure environment.

Related Question