[关闭]
@jfruan 2017-04-14T00:48:46.000000Z 字数 1093 阅读 5649

LaTeX算法排版

Latex


方式一

1. 需要包含

  1. \usepackage[noend]{algpseudocode}
  2. \usepackage{algorithmicx,algorithm}

2. 源码

  1. \begin{algorithm}[t]
  2. \caption{algorithm caption} %算法的名字
  3. \hspace*{0.02in} {\bf Input:} %算法的输入, \hspace*{0.02in}用来控制位置,同时利用 \\ 进行换行
  4. input parameters A, B, C\\
  5. \hspace*{0.02in} {\bf Output:} %算法的结果输出
  6. output result
  7. \begin{algorithmic}[1]
  8. \State some description % \State 后写一般语句
  9. \For{condition} % For 语句,需要和EndFor对应
  10.   \State ...
  11.   \If{condition} % If 语句,需要和EndIf对应
  12.     \State ...
  13.   \Else
  14.     \State ...
  15.   \EndIf
  16. \EndFor
  17. \While{condition} % While语句,需要和EndWhile对应
  18.   \State ...
  19. \EndWhile
  20. \State \Return result
  21. \end{algorithmic}
  22. \end{algorithm}

3. 结果截图

4. 注意

方式二

1. 需要包含

  1. \usepackage[ruled]{algorithm2e}

2. 源码

  1. \begin{algorithm}[H]
  2. \caption{algorithm caption}%算法名字
  3. \LinesNumbered %要求显示行号
  4. \KwIn{input parameters A, B, C}%输入参数
  5. \KwOut{output result}%输出
  6. some description\; %\;用于换行
  7. \For{condition}{
  8.   only if\;
  9.   \If{condition}{
  10.     1\;
  11.   }
  12. }
  13. \While{not at end of this document}{
  14.   if and else\;
  15.   \eIf{condition}{
  16.     1\;
  17.   }{
  18.     2\;
  19.   }
  20. }
  21. \ForEach{condition}{
  22.   \If{condition}{
  23.     1\;
  24.   }
  25. }
  26. \end{algorithm}

3. 结果截图

方式三

1. 需要包含

  1. \usepackage[ruled,vlined]{algorithm2e}

2. 源码

同方式二

3. 结果截图

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注