algorithmic
包中是否有类似于的\ElsIf
命令?algorithmicx
(我不希望每个嵌套的如果 缩进)。
答案1
是的,有:\ELSIF
。这是其中之一第一的例子取自algorithms
捆 文档(部分3.2如果-那么-否则陈述,第 3 页):
\documentclass{article}
\usepackage{algorithmic}
\begin{document}
\begin{algorithmic}
\IF{some condition is true}
\STATE do some processing
\ELSIF{some other condition is true}
\STATE do some different processing
\ELSIF{some even more bizarre condition is met}
\STATE do something else
\ELSE
\STATE do the default actions
\ENDIF
\end{algorithmic}
\end{document}
如果你正在使用algorithmicx
你必须使用\ElsIf
。下面是使用 的上述伪代码的镜像algpseudocode
:
\documentclass{article}
\usepackage{algpseudocode,algorithm}
\begin{document}
\begin{algorithmic}
\If{some condition is true}
\State do some processing
\ElsIf{some other condition is true}
\State do some different processing
\ElsIf{some even more bizarre condition is met}
\State do something else
\Else
\State do the default actions
\EndIf
\end{algorithmic}
\end{document}