\begin{algorithm}
\caption{AlgorithmCH election algorithm}
\label{algorithm}
\begin{algorithmic}[1]
\Procedure{CHElection}
\For{each node i }
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
Run Code Online (Sandbox Code Playgroud)
我有这段代码用于在 LATEX 中编写算法,但是! Missing number, treated as zero error当我指向该错误时,我收到了此错误 ( ),我在\Endfor 中看到了它。谁能告诉我为什么我会收到此错误?
这是我为编写算法添加的包
\usepackage[noend]{algpseudocode}
\usepackage[ruled,noresetcount,noend]{algorithm2e}
Run Code Online (Sandbox Code Playgroud)
algorithm2e使用时不要加载algpseudocode。前者创建一个algorithm浮动环境,但为了使用algorithmicfrom algpseudocode,您应该加载algorithm(从algorithmsbundle)。

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{AlgorithmCH election algorithm}
\label{algorithm}
\begin{algorithmic}[1]
\Procedure{CHElection}{}
\For{each node~$i$}
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
Run Code Online (Sandbox Code Playgroud)
另请注意 的第二个(强制)参数\Procedure,它指定传递给过程的参数。它也可以留空,但您需要明确包含它。
| 归档时间: |
|
| 查看次数: |
19497 次 |
| 最近记录: |