方式一
需要包含的
\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。
方式二
需要包含的
\usepackage[ruled]{algorithm2e} |
源碼
\begin{algorithm}[H] |
結果截圖
方式三
需要包含的
\usepackage[ruled,vlined]{algorithm2e} |
源碼
同方式二
結果截圖
如果有幫助,順手點個贊哦!我會好好努力的!!