Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

\usepackage{algorithm}
\usepackage{algorithmc}

%\begin{algorithm}[H]
\begin{algorithm*}
\caption{ASGP Merge and Pruning Step}
\label{alg:stuff}
\begin{algorithmic}[1]
\REQUIRE {$stuff$}
\STATE $stuff$
\RETURN $stuff$
\end{algorithmic}
%\end{algorithm}
\end{algorithm*}

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?

share|improve this question
1  
It may just be a typo while posting, or it may be correct, but should the second line be \usepackage{algorithmic} rather than \usepackage{algorithmc}? –  Scott H. May 15 '12 at 8:24

1 Answer 1

up vote 13 down vote accepted

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:

\documentclass{IEEEtran}
\usepackage{algpseudocode}

\begin{document}

\begin{figure}
\begin{algorithmic}[1]
\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$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\caption{Euclid's algorithm}\label{euclid}
\end{figure}

\end{document}

enter image description here

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

share|improve this answer
    
Unfortunately this is so ugly compared to the algorithm environment –  Martin Drozdik Nov 8 '13 at 8:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.