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

相关推荐
Am-Chestnuts5 天前
LaTeX 公式复制到 Word 怎么完美排版?DS随心转 三步保留可编辑公式
latex·办公效率·deepseek·word公式
lambo mercy6 天前
latex
latex
Am-Chestnuts6 天前
AI 公式复制到 Word 变乱的根因是什么?DS随心转 保留可编辑公式
latex·word导出·文档转换·ds随心转·公式乱码·ai公式
祺曦11 天前
overleaf写论文注意事项
论文·latex·overleaf
chillylight1 个月前
LaTeX 公式转 PNG / SVG:几种实用方案和使用场景对比
latex
sean9081 个月前
为 VitePress 加上 LaTeX 支持
latex·vitepress
GiantGo1 个月前
Texstudio编译参考文献出现问号
latex
程序员老赵1 个月前
Docker 部署 TeX Live:轻松搭建 LaTeX 论文排版编译平台
前端·docker·latex
小桥流水---人工智能3 个月前
TeX Live 安装报错:为什么修改 TEMP 和 TMP 后就能正常安装?
latex
西柚小萌新3 个月前
【论文写作】--LaTeX详细入门教程1
latex