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

相关推荐
weixin_394501451 天前
【Latex】NUDT-Latex毕业论文模板:成功编译食用
latex
西木九1 天前
win11 vscode 本地 latex 编译(Elsevier举例)
vscode·latex·学术写作
迷路爸爸1806 天前
无sudo权限远程连接Ubuntu服务器安装TeX Live实操记录(适配VS Code+LaTeX Workshop,含路径选择与卸载方案)
java·服务器·ubuntu·latex
冒冒菜菜10 天前
Visio导出清晰合适的pdf插入到Latex模板中
latex·visio·论文排版编辑
小锋学长生活大爆炸11 天前
【教程】使用VSCode编译LaTex
vscode·latex
JaredYe12 天前
纯 Node.js 编译 LaTeX:无需 TeX Live、无需宏包管理的工程级方案(node-latex-compiler)
node.js·latex·tectonic
bu_shuo23 天前
将AI生成的数学公式正确复制到word中
人工智能·chatgpt·word·latex
꧁Q༒ོγ꧂24 天前
LaTeX 语法入门指南
开发语言·latex
seasonsyy1 个月前
Latex中&符号的作用:对齐
latex·software
seasonsyy1 个月前
Latex:把图标以图片形式插入到某句话中
latex·software