latex加入算法块

  1. 加入要用的包
latex 复制代码
\usepackage[ruled]{algorithm2e}
  1. 定义代码块

    \begin{algorithm}[htb]
    \caption{This is a Example}
    \label{alg:example}
    \LinesNumbered
    \KwIn{A set of Points}
    \KwOut{A triangle mesh}
    Begin your Algorithm
    ......
    如果在一个代码块里想要换行的时候,在每一行的结尾加上;
    ......
    End your Algorithm
    \end{algorithm}

  2. 使用While

    \While{condition of judgment}{
    operation to be performed
    }

  3. 使用if......else

    \If{condition of judgment}{
    operation to be performed
    }
    \Else{
    operation to be performed
    }

  • 除了\If, \Else, \ElseIf之外,还有\uIf, \lIf, \uElse, \lElse, \uElseIf, \lElseIf等命令,他们的区别在于
    \If, \Else, \ElseIf都是会以end结尾
  • \uIf, \uElse, \uElseIf, 是不以end结尾的块级元素
  • \lIf, \lElse, \lElseIf 是不以end为结尾的行内元素
  • 在If-else结构中,\eIf 自带else(即 if 和 else 共用一个 end),而只是用 \If 和 \Else 的话则会多出一个end给Else。

Reference

https://www.cnblogs.com/X1OO/articles/17025753.html

https://blog.csdn.net/Bule_Zst/article/details/88848102

https://oldtang.com/8376.html

https://www.ctan.org/pkg/algorithm2e

https://mirrors.ustc.edu.cn/CTAN/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf

https://zhuanlan.zhihu.com/p/166418214

相关推荐
bu_shuo3 天前
将AI生成的数学公式正确复制到word中
人工智能·chatgpt·word·latex
꧁Q༒ོγ꧂3 天前
LaTeX 语法入门指南
开发语言·latex
seasonsyy5 天前
Latex中&符号的作用:对齐
latex·software
seasonsyy6 天前
Latex:把图标以图片形式插入到某句话中
latex·software
爱数模的小云11 天前
美赛LaTeX小白入门指南
数学建模·latex·数模美赛
时光Autistic11 天前
【环境配置】安装LaTeX并配置到PyCharm使用
ide·python·pycharm·latex
seasonsyy14 天前
CTex 2.8.0 更改编辑区文字大小
latex·ctex·winedit
seasonsyy15 天前
CTex2.8.0.125改变编辑区背景颜色
latex·ctex
seasonsyy17 天前
CTex 2.9.2 更改编辑区文字大小
latex·ctex·winedit
小桥流水---人工智能19 天前
tcolorbox 设置 breakable 后断页颜色失效问题及解决方案
latex