用LaTex写伪代码(使用宏包algorithm+algorithmic) |
您所在的位置:网站首页 › 代码输入怎么写 › 用LaTex写伪代码(使用宏包algorithm+algorithmic) |
https://math-linux.com/latex-26/faq/latex-faq/article/how-to-write-algorithm-and-pseudocode-in-latex-usepackage-algorithm-usepackage-algorithmic overleaf Algorithms 说明 添加宏 \usepackage{algorithm} \usepackage{algorithmic} 将 “Algorithm” 替换成 “算法” \floatname{algorithm}{算法} 可选用的代码结构由于版本的不同,有的版本支持下列命令仅开头大写 普通的一行语句 \STATEIf 语句 \IF{} \ENDIF \IF{} \ELSE \ENDIF \IF{} \ELSIF{} \ELSE \ENDIFFor 循环 \FOR{} \ENDFOR \FORALL{} \ENDFORWhile 循环 \WHILE{} \ENDWHILEDo-Until 循环 \REPEAT \UNTIL{}无限循环 \LOOP \ENDLOOP已知 \REQUIRE求 \ENSURE返回变量 \RETURN打印变量 \PRINT注释 \Comment{} 案例 \documentclass{article} \usepackage{algorithm} \usepackage{algpseudocode} \begin{document} \begin{algorithm} \caption{An algorithm with caption}\label{alg:cap} \begin{algorithmic} \Require $n \geq 0$ \Ensure $y = x^n$ \State $y \gets 1$ \State $X \gets x$ \State $N \gets n$ \While{$N \neq 0$} \If{$N$ is even} \State $X \gets X \times X$ \State $N \gets \frac{N}{2}$ \Comment{This is a comment} \ElsIf{$N$ is odd} \State $y \gets y \times X$ \State $N \gets N - 1$ \EndIf \EndWhile \end{algorithmic} \end{algorithm} \end{document} |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |