用LaTex写伪代码(使用宏包algorithm+algorithmic)

您所在的位置:网站首页 代码输入怎么写 用LaTex写伪代码(使用宏包algorithm+algorithmic)

用LaTex写伪代码(使用宏包algorithm+algorithmic)

2023-12-09 05:48| 来源: 网络整理| 查看: 265

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}{算法} 可选用的代码结构

由于版本的不同,有的版本支持下列命令仅开头大写

普通的一行语句

\STATE

If 语句

\IF{} \ENDIF \IF{} \ELSE \ENDIF \IF{} \ELSIF{} \ELSE \ENDIF

For 循环

\FOR{} \ENDFOR \FORALL{} \ENDFOR

While 循环

\WHILE{} \ENDWHILE

Do-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