The IEEEtran documentation suggests that I should not use the floating algorithm environment of algorithm2e.sty.
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’salgorithmic.sty
package or Szász
János’algorithmicx.sty
package (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 floatingalgorithm
environment of
algorithm.sty
(also by Williams and Brito) oralgorithm2e.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 thealgorithm.sty
or
algorithm2e.sty
float environments.
I tried using the suggested packages algorithmic
and algorithmicx
but I am not satisfied with the results and I would rather use the algorithm2e
package.
A colleague told me that the suggestion of IEEE applies only to the floating algorithm
environment of the package and not to the package itself. She suggested that I wrap the algorithm in a figure
environment.
I tried to simply wrap the entire algorithm in a figure
:
\documentclass[journal, a4paper]{IEEEtran}
\usepackage[ruled,norelsize]{algorithm2e}
\begin{document}
%\begin{figure}[!t]
\begin{algorithm}[h]
\caption{multiobjective DE}
initialize population $P = \left \{ X_{1}, ... , X_{N} \right \} $\;
\For( \emph{Evolutionary loop}){$g := 1$ to $G_{max}$}
{
Do things \;
Trim the population to size $N$ using nondominated sorting and diversity estimation \;
}
\end{algorithm}
%\end{figure}
\end{document}
But I get a
Not in outer par mode. \begin{algorithm}[h]
error. Obviously I cannot do it like this. How can I fix this?
Best Answer
You can follow this way.
First of all, you need to use the
H
specifier so to force thealgorithm
environment not to float.Then, since the
H
specifier is not allowed in two-column mode, you can use the workaround described by Werner in this answer, that is add the following lines in the preambleand issue the command
\removelatexerror
inside thefigure
environment.MWE:
Output:
If you want, you can now even add a
\caption
to thefigure
, e.g.yields