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

相关推荐
Sakuraba Ema3 天前
从零理解 MoE(Mixture of Experts)混合专家:原理、数学、稀疏性、专家数量影响与手写 PyTorch 实现
人工智能·pytorch·python·深度学习·数学·llm·latex
简宸~4 天前
VS Code + LaTex + SumatraPDF联合使用指南
java·vscode·latex·sumatrapdf
bu_shuo9 天前
AI生成的数学公式复制为LaTeX插件
ai·chatgpt·latex·gemini·千问·豆包·数学公式复制
还不秃顶的计科生11 天前
latex代码裁剪pdf图片
pdf·latex
小哈里1 个月前
【科研】ACM MM 论文 Latex 投稿模板修改(基于sample-sigconf-authordraft-v2.16)
人工智能·llm·科研·latex·cv·overleaf
007张三丰1 个月前
Markdown+Pandoc写论文,完美支持LaTeX公式、Mermaid图表、参考文献
markdown·pandoc·latex·mermaid·mermaid图表·markdown写论文
today__present1 个月前
Latex figure 报错显示 Float lost
latex
weixin_394501452 个月前
【Latex】NUDT-Latex毕业论文模板:成功编译食用
latex
西木九2 个月前
win11 vscode 本地 latex 编译(Elsevier举例)
vscode·latex·学术写作
迷路爸爸1802 个月前
无sudo权限远程连接Ubuntu服务器安装TeX Live实操记录(适配VS Code+LaTeX Workshop,含路径选择与卸载方案)
java·服务器·ubuntu·latex