
algorithmic
package 中是否有類似\ElsIf
in 的指令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}