LaTeX中使用algorithm2e包来书写伪代码是一种常见且优雅的方式。 algorithm2e包简介 algorithm2e是一个用于在LaTeX中排版算法的宏包,它提供了丰富的命令和选项,使得书写伪代码变得既简单又美观。 基本使用步骤 引入宏包: 在LaTeX文档的导言区(\begin{document}之前)引入algorithm2e宏包,并可以指定一些选项来定制算法的显...
\usepackage[ruled,vlined]{algorithm2e} \begin{document} \renewcommand{\listalgorithmcfname}{算\ 法\ 目\ 录} %生成算法目录命令 \listofalgorithms \renewcommand{\algorithmcfname}{算法} \SetKwInOut{KwIn}{输入} \SetKwInOut{KwOut}{输出} \begin{algorithm} \renewcommand{\thealgocf}{3-1} \SetAl...
在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...
一般会接触到的包有algorithm、algorithmic、algorithmicx、algorithm2e这四种包。 algorithm用于给伪代码提供一个浮动体环境,防止其换页或其他因素导致的内容中断,从而跨页显示。 algorithmic用于编辑伪代码的内容,一些for、while、if等语句通过该包中的命令进行编写。
{algorithm}[t] \caption{algorithmcaption} %算法的名字 \hspace*{0.02in} {\bfInput:} %算法的输入, \hspace*{0.02in}用来控制...没有 EndWhile,否则会出现 Some blocks are not closed。 方式二 需要包含的\usepackage[ruled]{algorithm2e} 源码 ...
Algorithm2e本身不支持Do-While结构(支持的是While-Do),需要自行定义。不过自行定义并不难,因为宏包中内置了Repeat-Until结构,在Algorithm2e中是“宏指令(Repeat macros)”的一种[1]自定义宏指令 定义完之后,就可以在伪代码块中使用如下命令调用 完整例程:写在最后 LaTeX,说难也难,说不难也...
{algorithmic} \end{algorithm} 结果截图 注意 1. 关键字的大小写问题,否则会出现 Undefined control sequence.2. 控制流要前后对应。如果有While,但没有EndWhile,否则会出现 Some blocks are not closed。 方式二 需要包含的\usepackage[ruled]{algorithm2e} 源码 ...
\KwOut{how to write algorithm with \LaTeX2e } initialization\; \While{not at end ofthisdocument}{ read current\; \eIf{understand} { go to next section\; current section becomesthisone\; } { go back to the beginning of current section\; ...
LaTeX书写伪代码时,尽管Algorithm2e不直接支持Do-While结构,但可通过自定义实现,这并不复杂。宏包中已经包含了Repeat-Until结构,作为"宏指令"的基础。例如,定义自定义宏指令后,可以在伪代码块中使用相应命令。以下是几个实际操作的例子:1. 空白文档中的原始例子:2. 添加间隔和强调,以及if条件...