准备工作

  1. 选择插入—对象—Aurora Equation,确定。

image-20210426105115227

img

  1. 导入所需库[1]
\makeatletter
\newif\if@restonecol
\makeatother
\let\algorithm\relax
\let\endalgorithm\relax
\usepackage[linesnumbered,ruled]{algorithm2e}%[ruled,vlined]{
\usepackage{algpseudocode}
\usepackage{amsmath}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm 

语法

if

\If{conditions}{
	sentences
}

if-else

\eIf{conditions}{
	sentences
}{
	else-sentences
}

if-elseif-else

for循环

\For{condition}{
	...
}

foreach循环

\lForEach{element $e$ of the line $i$}{\FindCompress{p}}

while循环

\While{not at end of this document}{
    a while loop including a repeat--until loop\;
}

begin-end

\Begin{
	......
}

带有repeat的while循环

\While{not at end of this document}{
    a while loop including a repeat--until loop\;
    \Repeat{this end condition}{
    	do this things\;
    }
}

小技巧

  1. 算法不自动编号

    \begin{algorithm}前加上\setcounter{algocf}{1}

  2. \Return好像与\Begin{block}冲突

未完待续


  1. 前五句是防止与其他包冲突 ↩︎