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

相关推荐
Jovin Giogic4 天前
简明教程:记录 Ubuntu系统命令行安装TexLive,配置vscode
linux·vscode·ubuntu·latex·texlive
verse_armour7 天前
markdown插入文献引用并导出pdf
pdf·markdown·pandoc·latex
摸森堡8 天前
vs code + latex使用攻略
latex
我的golang之路果然有问题13 天前
word中latex插入矩阵的语法问题
笔记·学习·矩阵·word·latex·template method·分享
钱彬 (Qian Bin)15 天前
从零开始发表SCI论文—第1篇:安装Latex写作工具
latex·vs code·sci论文·环境准备
他来自江湖19 天前
西南科技大学,研究生开题报告latex模板
科技·latex·开题报告·西南科技大学
Invinc-Z20 天前
LaTeX 个人简历模板
latex
嘿嘻哈呀1 个月前
MaxTex下载及LaTex环境配置
latex·maxtex·latex workshop
喝凉白开都长肉的大胖子1 个月前
比较 main.tex 的两个不同版本(例如旧版和新版),并生成一个带有修改标记(如删除线、高亮、修订注释)的 PDF 或文本输出。
pdf·latex
麻雀无能为力1 个月前
LaTeX基础使用
latex