\begin{algorithm}
\SetNoLine
\DontPrintSemicolon % Some LaTeX compilers require you to use\dontprintsemicolon instead
\KwIn{A finite set $A=\{a_1, a_2, \ldots, a_n\}$ of integers}
\KwOut{The largest element in the set}
$max \gets a_1$\;
\For{$i \gets 2$ \textbf{to} $n$} {
\If{$a_i > max$} {
$max \gets a_i$\;
}
}
\Return{$max$}\;
\caption{{\sc Max} finds the maximum number}
\label{algo:max}
\end{algorithm}
这里 \SetNoLine 不起作用
答案1
文档尚未更新(或者我没有找到信息):\SetNoLine
已被弃用,并替换为\SetAlgoNoLine
:
\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
{\SetAlgoNoLine%
\begin{algorithm}
\DontPrintSemicolon % Some LaTeX compilers require you to use\dontprintsemicolon instead
\KwIn{A finite set $A=\{a_1, a_2, \ldots, a_n\}$ of integers}
\KwOut{The largest element in the set}
$max \gets a_1$\;
\For{$i \gets 2$ \textbf{to} $n$} {
\If{$a_i > max$} {
$max \gets a_i$\;
}
}
\Return{$max$}\;
\caption{{\sc Max} finds the maximum number}
\label{algo:max}
\end{algorithm}}%
\begin{algorithm}
%
\DontPrintSemicolon % Some LaTeX compilers require you to use\dontprintsemicolon instead
\KwIn{A finite set $A=\{a_1, a_2, \ldots, a_n\}$ of integers}
\KwOut{The largest element in the set}
$max \gets a_1$\;
\For{$i \gets 2$ \textbf{to} $n$} {
\If{$a_i > max$} {
$max \gets a_i$\;
}
}
\Return{$max$}\;
\caption{{\sc Max} finds the maximum number}
\label{algo:max}
\end{algorithm}
\end{document}
如果希望整个文档没有垂直线,您可以选择noline
:
\usepackage[noline]{algorithm2e}