0

I found this question explaining how to use algorithm2e package with IEEEtran class. However I would like to be able also to use the algorithmic package.

For the following code:

\begin{figure}[!t]
 \removelatexerror
  \begin{algorithm}[H]
    \begin{algorithmic}
     \For( \emph{Evolutionary loop}){$g := 1$ to $G_{max}$}
     {
        \State Do things \;
        \State Trim the population to size $N$ using nondominated sorting and diversity estimation \;
     }
    \end{algorithmic}
  \end{algorithm}
\end{figure}

I am getting an error:

ERROR: You can't use `\prevdepth' in horizontal mode.

--- TeX said ---
\nointerlineskip ->\prevdepth 
                              -\@m \p@ 

I am reusing preamble from the original question:

\usepackage[ruled,norelsize]{algorithm2e}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
\usepackage{algpseudocode,algorithmicx}

I would highly appreciate if you could help me to fix the problem.

UPD Full minimal example:

\documentclass[journal, a4paper]{IEEEtran}

\usepackage[ruled,norelsize]{algorithm2e}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
\usepackage{algpseudocode,algorithmicx}

\begin{document}

\begin{figure}[!t]
 \removelatexerror
  \begin{algorithm}[H]
    \begin{algorithmic}
      \For{\texttt{<some condition>}}
        \State \texttt{<do stuff>}
      \EndFor
    \end{algorithmic}
  \end{algorithm}
\end{figure}

\end{document}
desa
  • 153

1 Answers1

0

The algpseudocode package is not compatible with algorithm2e.

\documentclass[journal, a4paper]{IEEEtran}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}

\begin{algorithmic}
  \For{\texttt{<some condition>}}
    \State \texttt{<do stuff>}
  \EndFor
\end{algorithmic}

\end{algorithm}

\end{document}
egreg
  • 1,121,712