写论文时要陈述自己提出来的算法,遂学。
引入宏包:
\usepackage{algorithm}
\usepackage{algorithmic}
重新定义样式:
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
下面是一些简单的使用:
\begin{algorithm}[H]
\caption{algorithm 1}
\begin{algorithmic}[1] % 此处的[1]控制一下算法中的每句前面都有标号
\REQUIRE input
\ENSURE output
\STATE {Step A}
\STATE {Step B}
\FOR {$ i = 1 $; $ i < n $; $ i ++ $ }
\STATE {Step C}
\ENDFOR
\WHILE {$ |E_n| \leq L_1 $}
\STATE {Step D}
\ENDWHILE
\FORALL {...}
\STATE {Step E}
\ENDFOR
\IF {condition}
\STATE {Step F}
\ENDIF
\end{algorithmic}
\end{algorithm}
效果图:
algorithm2e
引入宏包:
\usepackage[ruled]{algorithm2e}
常见用法:
\begin{algorithm}[t]
\caption{Algorithm Test}
\label{algorithm:test}
\LinesNumbered
\KwIn {input}
\KwOut {output}
\For{i = 1 to n}{
\eIf{condition} {
Step A \tcp*{comment inline}
\tcp{new line comment}
} {
i ++;
}
}
\While{condition}{
do something
}
Step B \;
Step C \;
Step D ;
\end{algorithm}
效果图:
如果引用宏包时附带其他参数,如:
\usepackage[ruled,vlined]{algorithm2e}
效果:
更详细的用法详见文档:
本文作者:博主: gyrojeff 文章标题:LaTeX的算法 | 伪代码排版
本文地址:https://cloud.tencent.com/developer/article/1827328
版权说明:若无注明,本文皆为“gyro永不抽风!”原创,转载请保留文章出处。
许可协议:署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 转载请保留原文链接及作者!
我的博客即将同步至腾讯云+社区,邀请大家一同入驻
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有