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

相关推荐
Cc小跟班5 天前
LaTeX 中给单个/部分参考文献标记颜色(BibTeX 文献引用)
latex·论文写作
Invinc-Z6 天前
$\LaTeX{}$之快速编译和删除中间文件
latex
Invinc-Z6 天前
$\LaTeX{}$之图片使用
latex
Time_Memory_cici7 天前
WinEdt编译tex文件失败解决办法
latex
喝凉白开都长肉的大胖子1 个月前
latex中“itemize”
latex
cxylay1 个月前
LaTeX(排版系统)Texlive(环境)Vscode(编辑器)环境配置与安装
ide·vscode·编辑器·latex·texlive
米饭的白色1 个月前
vscode/trae 的 settings.json 中配置 latex 的一些记录
vscode·json·latex
Chensf20211 个月前
用latex+vscode+ctex写毕业论文
vscode·论文·latex·ctex
nlp研究牲2 个月前
latex中既控制列内容位置又控制列宽,使用>{\centering\arraybackslash}p{0.85cm}
服务器·前端·人工智能·算法·latex
山登绝顶我为峰 3(^v^)32 个月前
如何录制带备注的演示文稿(LaTex Beamer + Pympress)
c++·线性代数·算法·计算机·密码学·音视频·latex