下面是由两个小算法组成的 MWE,演示了不必要地使用 {...} 环境如何导致 LaTeX 出现意外行为,即覆盖行号,如第二个算法所示。
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Algorithm 1}
\label{Algorithm:Alg1}
\begin{algorithmic}[1]
\Function {Algorithm1}{}
\If{Condition 1}
\State Statement 1
\Else
\State Statement 2
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Algorithm 2}
\label{Algorithm:Alg2}
\begin{algorithmic}[1]
\Function {Algorithm2}{}
\If{Condition 1}
\State Statement 1
\Else
{
\State Statement 2
}
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}