在If-else结构中,\eIf 自带else(即 if 和 else 共用一个 end),而只是用 \If 和 \Else 的话则会多出一个end给Else。 此外,Algorithm2e 本身不支持 Do-While 结构(支持的是 While-Do),需要自行定义。不过自行定义并不难,因为宏包中内置了 Repeat-Until 结构,在 Algorithm2e 中是“宏指令(Repeat macros)...
\begin{algorithm}[H]\KwData{thistext}\KwResult{how to write algorithmwith\LaTeX2e }initialization\;\While{not at endofthisdocument}{read current\;\Repeat{thisend condition}{dothese things\;}\eIf{understand}{go to next section\;current sec...
\While{notatendofthis document}{ ifandelse\; \eIf{condition}{ 1\; }{ 2\; } } \ForEach{condition}{ \If{condition}{ 1\; } } return \end{algorithm} \end{document} 效果图如下: 宏包参数的使用 这句代码表示引用宏包algorithm2e \usepackage[linesnumbered,ruled,vlined]{algorithm2e} 下面是...
Algorithm2e本身不支持Do-While结构(支持的是While-Do),需要自行定义。不过自行定义并不难,因为宏包中内置了Repeat-Until结构,在Algorithm2e中是“宏指令(Repeat macros)”的一种[1]自定义宏指令 定义完之后,就可以在伪代码块中使用如下命令调用 完整例程:写在最后 LaTeX,说难也难,说不难也...
LaTeX书写伪代码时,尽管Algorithm2e不直接支持Do-While结构,但可通过自定义实现,这并不复杂。宏包中已经包含了Repeat-Until结构,作为"宏指令"的基础。例如,定义自定义宏指令后,可以在伪代码块中使用相应命令。以下是几个实际操作的例子:1. 空白文档中的原始例子:2. 添加间隔和强调,以及if条件...
一般会接触到的包有algorithm、algorithmic、algorithmicx、algorithm2e这四种包。 algorithm用于给伪代码提供一个浮动体环境,防止其换页或其他因素导致的内容中断,从而跨页显示。 algorithmic用于编辑伪代码的内容,一些for、while、if等语句通过该包中的命令进行编写。
LATEX——algorithm2e 伪代码书写模板 在为代码的各种模板中,algorithm2e的效果看起来比较舒服,更加简洁。 首先给出例子: \begin{algorithm}[t] \caption{example} \label{example} \begin{small} \BlankLine \KwIn{input} \KwOut{output} line 1... ...
在 \begin{document} 前输入 \usepackage[options]{algorithm2e}。options 包括:language option、兼容性问题、环境显示和使用以及代码排版 1.1 language option 默认为 english,支持部分其他语言(不包括中文),首字母需要小写。这里不做详细介绍。1.2 兼容性问题 这部分似乎不太常用,包括 algo2e、...
latex algorithm2e 注释 本文将介绍 LaTeX 中 algorithm2e 宏包的注释功能。algorithm2e 宏包是一款用于排版算法的宏包,其注释功能可以帮助我们更好地理 解和阅读算法代码。 使用algorithm2e 宏包时,我们需要在导言区加载宏包: ```latex usepackage[ruled,linesnumbered]{algorithm2e} ``` 其中,ruled 表示算法的...
{algorithmic} \end{algorithm} 结果截图 注意 1. 关键字的大小写问题,否则会出现 Undefined control sequence.2. 控制流要前后对应。如果有While,但没有EndWhile,否则会出现 Some blocks are not closed。 方式二 需要包含的\usepackage[ruled]{algorithm2e} 源码 ...