我发现这个问题解释如何使用algorithm2e
带有 IEEEtran 类的包。不过,我也希望能够使用该algorithmic
包。
对于以下代码:
\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}
我收到一个错误:
ERROR: You can't use `\prevdepth' in horizontal mode.
--- TeX said ---
\nointerlineskip ->\prevdepth
-\@m \p@
我重复使用原始问题的序言:
\usepackage[ruled,norelsize]{algorithm2e}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
\usepackage{algpseudocode,algorithmicx}
如果您能帮助我解决这个问题我将非常感激。
更新型多巴胺完整最小示例:
\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}
答案1
该algpseudocode
包与 不兼容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}