在Latex中使用algorithm2e显示if-elseif-else-endif 今天看了导师给的Latex的论文,突然发现原来算法有专门的algorithm去显示,感觉很新奇,赶紧学习一波。 在学习过程中,发现了一个问题,就是,不知道如何显示if-elseif-else-endif,在网上也查了一些资料,不过有关algorithm2e的资料很少,于是只能自己去看文档了,文档传送...
在LaTeX中编写包含if-else结构的算法,你可以使用algorithm和algorithmic宏包,或者使用algorithm2e宏包。以下是两种方法的详细解释和示例代码: 方法一:使用algorithm和algorithmic宏包 引入宏包: 在文档的导言区(即\begin{document}之前)引入algorithm和algorithmic宏包。 latex \usepackage{algorithm} \usepackage{algorithmic...
在If-else结构中,\eIf 自带else(即 if 和 else 共用一个 end),而只是用 \If 和 \Else 的话则会多出一个end给Else。 此外,Algorithm2e 本身不支持 Do-While 结构(支持的是 While-Do),需要自行定义。不过自行定义并不难,因为宏包中内置了 Repeat-Until 结构,在 Algorithm2e 中是“宏指令(Repeat macros)...
elseif-content} \Else{ else-content} 感谢
如果你不想让你的伪代码叫做 'Algorithm 编号', 可以使用\renewcommand{\algorithmcfname}{算法名}命令来修改。 除了\If, \Else, \ElseIf之外,还有\uIf, \lIf, \uElse, \lElse, \uElseIf, \lElseIf等命令,他们的区别在于 \If, \Else, \ElseIf都是会以end结尾 ...
在Latex中使用algorithm2e显示if-elseif-else-endif 今天看了导师给的Latex的论文,突然发现原来算法有专门的algorithm去显示,感觉很新奇,赶紧学习一波。 在学习过程中,发现了一个问题,就是,不知道如何显示if-elseif-else-endif,在网上也查了一些资料,不过有关algorithm2e的资料很少,于是只能自己去看文档了,文档传送门...
写在前面:algorithm2e 的代码可真丑啊!比 algorithm 那一套丑多了! 本文代码在 overleaf 上编译。 reference: algorithm2e.sty — package for algorithms 1 宏包 在\begin{document} 前输入 \usepackage[options]{algorithm2e}。 options 包括:language option、compatibility issue、environment display and use 和...
现在,我们在输入输出中间加一点点间隔,然后给算法的某些行进行强调,再给if条件加上注释呢 \def\SetClass{article}\documentclass{\SetClass}\usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}\begin{document}\IncMargin{1em}\begin{algorith...
首先,送上algorithm2e官方文档 \IncMargin{1em} % 行号不向外突出 \begin{algorithm} \SetAlgoNoLine % 不要算法对齐竖线 \SetKwInOut{Input}{\textbf{Input}}\SetKwInOut{Output}{\textbf{Output}} % 替换输入输出关键词,textbf中的词汇可以换成自己需要的内容 \Input{A} % 输入\Output{B} % 输出\...
ifandelse\; \eIf{condition}{ 1\; }{ 2\; } } \ForEach{condition}{ \If{condition}{ 1\; } } return \end{algorithm} \end{document} 效果图如下: 宏包参数的使用 这句代码表示引用宏包algorithm2e \usepackage[linesnumbered,ruled,vlined]{algorithm2e} ...