algorithm2e笔记,记录一下常规操作

先贴一张图片:
在这里插入图片描述
记录一下这几种用法:

1 常规示例代码及包导入;

在这里插入图片描述
在下载完AuroraMikTex之后,打开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}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值