我正在用 latex 编写算法,但是算法中有很多end-if
和end-while
,这使得它不专业且难看。有没有办法从 latex 输出中删除它们?
\IF{condition}
\IF{another condition}
\STATE do something
\STATE do something else
\ELSE
\STATE do it
\ENDIF
\ELSE
\IF{condition}
\STATE do something
\STATE do another thing
\ELSE
\IF{condition}
\STATE function
\ENDIF
\ENDIF
\ENDIF
答案1
我建议你换成更通用的algorithmicx
包;使用noend选项,你可以实现你想要的:
\documentclass{article}
\usepackage[noend]{algcompatible}
\begin{document}
\begin{algorithmic}
\IF{condition}
\IF{another condition}
\STATE do something
\STATE do something else
\ELSE
\STATE do it
\ENDIF
\ELSE
\IF{condition}
\STATE do something
\STATE do another thing
\ELSE
\IF{condition}
\STATE function
\ENDIF
\ENDIF
\ENDIF
\end{algorithmic}
\end{document}
我使用了algcompatible
包的变体来完全兼容的algorithmic
语法,但我还建议您更改为algpseudocode
(语法非常相似);这是您的代码algpseudocode
(唯一的区别是使用的大小写类型):
\documentclass{article}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithmic}
\If{condition}
\If{another condition}
\State do something
\State do something else
\Else
\State do it
\EndIf
\Else
\If{condition}
\State do something
\State do another thing
\Else
\If{condition}
\State function
\EndIf
\EndIf
\EndIf
\end{algorithmic}
\end{document}