algorithm2e是latex上用来写算法的包。
目前还有很多,比如algorithmc等。两者的语法不同。
使用时要先导入包:
\usepackage[ruled,linesnumbered]{algorithm2e}
下面贴出一个示例:
\begin{algorithm}[t]
\caption{Event Detection}
\label{algo:event}
\LinesNumbered
\KwIn{FFT Bins $B_{1}, B_{2}, B_{3}, ..., B_{n}$}
\KwOut{Event start point $S$, end point $E$}
\For{i=1:n}{
\eIf{max($B_{i}$) : max($B_{(i+4)}$)$>$-80}{
$S$=i; \tcp*{Start Point}
\For{j=S:n}{
\eIf{max($B_{j}$) : max($B_{(j+4)}$)$<$-100}{
$E$=j; \tcp*{End Point}
Return [$S,E$];
}{j++;}
}
}{
i++;}
}
\end{algorithm}
得到的结果如下: