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

相关推荐
嘿嘻哈呀6 天前
MaxTex下载及LaTex环境配置
latex·maxtex·latex workshop
喝凉白开都长肉的大胖子15 天前
比较 main.tex 的两个不同版本(例如旧版和新版),并生成一个带有修改标记(如删除线、高亮、修订注释)的 PDF 或文本输出。
pdf·latex
麻雀无能为力20 天前
LaTeX基础使用
latex
Invinc-Z23 天前
国内外期刊和学位论文等LaTeX模板编译报错如何解决
latex
Invinc-Z24 天前
一份简短的LaTeX相关术语的介绍
latex
吴禅染1 个月前
MDPI投稿overleaf:bib问题
latex
Source.Liu2 个月前
【LaTeX】 12 LaTeX 参考文献管理
latex
热爱生活的五柒2 个月前
排版使用latex排版还是word排版更容易通过mdpi remote sensing的审稿?
word·latex
Cc小跟班2 个月前
LaTeX 中给单个/部分参考文献标记颜色(BibTeX 文献引用)
latex·论文写作
Invinc-Z2 个月前
$\LaTeX{}$之快速编译和删除中间文件
latex