先贴一张图片:
记录一下这几种用法:
1 常规示例代码及包导入;
在下载完Aurora
、MikTex
之后,打开Word
,
Aurora
-> Inline Equation
-> Propertity
导入algorithm2e
包,中括号代表一些配置,详见algorithm2e.pdf-7.1节
\usepackage[ruled,boxed,commentsnumbered]{algorithm2e}
然后键入常规示例
\SetKwRepeat{Do}{do}{while}%
\begin{document}
\begin{algorithm}[H]
\KwIn{this text}
\KwOut{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\Repeat{this end condition}{
do these things\;
}
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
\Do{this end condition}{
do these things\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}
于是就渲染出了常规的三线表格,但是似乎少了行号;
2 添加行号;
添加行号十分简单,就是在导入包的时候,添加一个配置
\usepackage[ruled,boxed,commentsnumbered,linesnumbered]{algorithm2e}
3 修改算法编号;
简单的修改编号,可以直接在\begin{algorithm}[H]
的前面set
一下,例如这里将编号改为5(从0开始)
\setcounter{algocf}{4}
\begin{algorithm}[H]
然后,如果想改成算法4-1
可以直接在\begin{algorithm}[H]
的里面,自定义一下编号
\setcounter{algocf}{4}
附上最终的完整代码:
\SetKwRepeat{Do}{do}{while}%
\begin{document}
\begin{algorithm}[H]
\renewcommand{\thealgocf}{4-1}
\KwIn{this text}
\KwOut{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\Repeat{this end condition}{
do these things\;
}
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
\Do{this end condition}{
do these things\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}