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

相关推荐
山登绝顶我为峰 3(^v^)34 天前
如何录制带备注的演示文稿(LaTex Beamer + Pympress)
c++·线性代数·算法·计算机·密码学·音视频·latex
秋窗77 天前
Mac 部署Latex OCR并优化体验(打包成App并支持全局快捷键)
macos·ocr·latex
八一考研数学竞赛22 天前
第十七届全国大学生数学竞赛初赛模拟试题
学习·数学·latex·全国大学生数学竞赛
momo8701 个月前
当你安装TeX Live 2025 却遇到中文用户名时。。。
latex
星夜钢琴手1 个月前
缩小 IEEE 会议论文 LaTeX 模板标题、作者信息和正文的间距
latex·ieee conference
cnkeysky1 个月前
vscode 配置 latex
vscode·latex
磁悬浮青蛙呱呱呱1 个月前
xdvipdfmx:fatal: File ended prematurely. No output PDF file written.
latex
EtherWanderer1 个月前
Markdown 到 LaTeX:Overleaf 学习笔记
笔记·学习·latex
hallo-ooo2 个月前
【LaTex】基础语法入门
latex
伊织code2 个月前
LaTeX OCR - 数学公式识别系统
python·ai·ocr·latex·数学公式识别