[科研小记]在Latex中将算法进行分页显示
代码送上,通过前两个algorithm即可实现将example中的algorithm分成任意两段,且第二段算法可以实现无标题、任意行号开始:
\documentclass{report}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\begin{document}
\begin{algorithm}
\caption{abc dcc}
\LinesNumbered
% This is to hide end and get the last vertical line straight
\SetKwBlock{Begin}{Begin}{}
\SetAlgoLined
\SetKwProg{Loop}{LOOP}{}{}
\Begin{
$\mathcal{E} \leftarrow \emptyset$\;
\SetAlgoVlined \Loop {$ab \gets cd$}{
$abcd$\\
$abdc $ }
}
\end{algorithm}
\SetNlSty{texttt}{(}{)}
\begin{algorithm}
\LinesNumbered
\setcounter{AlgoLine}{12} % set line number
% This is to restore vline mode if you did not take the package as \usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\SetAlgoVlined
%This is to hide Begin keyword
\SetKwBlock{Begin}{}{end}
\SetKwProg{Loop}{LOOP}{}{}
\Begin{
$\mathcal{E} \leftarrow \emptyset$\;
$\mathcal{E} \leftarrow \emptyset$\;
\SetAlgoVlined \Loop {$ab \gets cd$}{
$abcd$\\
$abdc $ }
$\mathcal{E} \leftarrow \emptyset$\;
$\mathcal{E} \leftarrow \emptyset$\;
$\mathcal{E} \leftarrow \emptyset$\;
}
\end{algorithm}
\begin{algorithm}
\caption{fbf jfjf}
\LinesNumbered
% This is to restore vline mode if you did not take the package as \usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\SetAlgoVlined
%This is to hide Begin keyword
\SetKwProg{Loop}{LOOP}{}{}
\SetKwBlock{Begin}{loop3}{end}
\Begin{
$\mathcal{E} \leftarrow \emptyset$\;
$\mathcal{E} \leftarrow \emptyset$\;
\SetAlgoVlined \Loop {$ab \gets cd$}{
$abcd$\\
$abdc $ }
$\mathcal{E} \leftarrow \emptyset$\;
$\mathcal{E} \leftarrow \emptyset$\;
$\mathcal{E} \leftarrow \emptyset$\;
}
\end{algorithm}
\end{document}
显示效果如下:
相关参考网站