
正文
LaTeX算法排版
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
需要包含的
\usepackage[noend]{algpseudocode}
\usepackage{algorithmicx,algorithm}
源码
\begin{algorithm}[t]
\caption{algorithm caption} %算法的名字
\hspace*{0.02in} {\bf Input:} %算法的输入, \hspace*{0.02in}用来控制位置,同时利用 \\ 进行换行
input parameters A, B, C\\
\hspace*{0.02in} {\bf Output:} %算法的结果输出
output result
\begin{algorithmic}[1]
\State some description % \State 后写一般语句
\For{condition} % For 语句,需要和EndFor对应
\State ...
\If{condition} % If 语句,需要和EndIf对应
\State ...
\Else
\State ...
\EndIf
\EndFor
\While{condition} % While语句,需要和EndWhile对应
\State ...
\EndWhile
\State \Return result
\end{algorithmic}
\end{algorithm}
结果截图

注意
1. 关键字的大小写问题,否则会出现 Undefined control sequence.
2. 控制流要前后对应。如果有 While,但没有 EndWhile,否则会出现 Some blocks are not closed。







