网站标签spanb站网站推广mmm
1 首先导入包:
按需要添加或者删除option,但是algochapter
是必须的。
\usepackage[linesnumbered,ruled,algochapter]{algorithm2e}
各个option的作用如下:
您好,这是Bing。我可以帮您解释algorithm2e包中这几个option的意思。😊
linesnumbered
: 这个选项表示在伪代码的每一行前面显示行号,方便引用和阅读。ruled
: 这个选项表示在伪代码的顶部和底部画一条横线,并且让标题左对齐。algochapter
(或chapter
): 这个选项表示在伪代码的标题中加入章节号,例如Algorithm 1.1,Algorithm 1.2等。
2 举例
\renewcommand{\algorithmcfname}{算法} %<---细节与重点
\SetKwInput{KwIn}{输入} %<---细节与重点
\SetKwInput{KwOut}{输出} %<---细节与重点\begin{algorithm}[h!t]\renewcommand{\thealgocf}{\thechapter-\arabic{algocf}} %<---细节与重点(实现连字符编号)\SetAlgoLined\KwIn{步长阈值$\varepsilon_{2}$,残差阈值$\varepsilon_{3}$}\KwOut{满足要求的关节角向量$\symbf{\theta}$}\SetKwBlock{Beginn}{beginn}{ende}\Begin{$k:=0$;\While{$($\textbf{not} $stop)$ \textbf{and} $ \left(k < k_{\rm max} \right)$}{$k:=k+1$;\eIf{$\left\|{\symbf{\varDelta} \symbf{\theta}}\right\| \leq \varepsilon_{2} \left(\left\|\symbf{\theta}\right\|+ \varepsilon_{2}\right)$}{$stop:=true$}{$\symbf{\theta}_{\rm new}:=\symbf{\theta}+{\symbf{\varDelta} \symbf{\theta}}$\eIf{$\varrho > 0$}{$\symbf{\theta}:=\symbf{\theta}_{\rm new}$; \quad 更新$\symbf{J}$}{$\mu:=\mu * \nu$; \quad $\nu:=2 * \nu$ }}}}% end for begin\caption{算法伪代码}\label{pseudocode}
\end{algorithm}
显示效果: