当我运行以下代码时,pdf 正在生成,但出现错误。
\documentclass[12pt,a4paper,oneside,oldfontcommands]{memoir}
\usepackage{algorithm2e}
\usepackage{algorithmicx}
\begin{document}
The following is an example algorithm
\begin{algorithm}[ht!]
\caption{Algorithm}
Set count = 1 \linebreak
\While{count $\le$ V}{
count $\gets$ count + 1
}
\While{dataa $\ne \phi$}{
\For{V $\epsilon$ data}
{ \For{a \textless d}
{ \If{ccc}
{
statements;
}
\ElseIf{cond2}
{
statements;
}
\EndIf
} \EndFor
} \EndFor
}
\end{algorithm}
\end{document}
答案1
不要混合algorithmicx
和algorithm2e
。使用其中一个即可。使用后者时,可以使用以下方法:
\documentclass{article}
\usepackage{algorithm2e,amsmath}
\begin{document}
The following is an example algorithm
\begin{algorithm}[ht!]
\caption{Algorithm}
Set $\text{count} = 1$\;
\While{$\text{count} \leq V$}{
$\text{count} \gets \text{count} + 1 $
}
\While{$\text{data} \neq \phi$}{
\For{$V \in \text{data}$}{
\For{$a < d$}{
\If{ccc}{
statements\;
}
\ElseIf{cond2}{
statements\;
}
}
}
}
\end{algorithm}
\end{document}