Is there an option in algorithm2e to split the algorithm over several pages? Please no answer with "use algorithmic or listings packages". algorithm2e is the best package for algorithms in latex, so I want to get it running with this package.
- 262,582
- 171
2 Answers
From the algorithm2e documentation:
Caution: algorithms cannot be cut
You could use instead the algorithmicx package which offers you improved functionality and offers the possibility of breaking long algorithms (see Section 2.6 Breaking up long algorithms of the package documentation).
- 505,128
-
Not much better though, it still requires you to manually break the algorithm block. Could mean massive reflow of your document. – Code Different Nov 15 '13 at 02:42
-
8
algorithmicxhasn't been maintained since 2005!algorithm2ehowever is still active (check CTAN), so in my view it is the best package available. – MP0 Aug 11 '16 at 12:44
A workaround for the problem is to find good place to break, split the algorithm, and use the next to
\setcounter{AlgoLine}{20}
The problem with embedded blocks could be solved with invisible begins/ends. The Begin keyword can be hidden by:
\SetKwBlock{Begin}{}{end}
Example:
The first part:
\begin{algorithm}
\LinesNumbered
% This is to hide end and get the last vertical line straight
\SetKwBlock{Begin}{Begin}{}
\SetAlgoLined
\Begin{
% This is to restore vline mode
\SetAlgoVlined
$\mathcal{E} \leftarrow \emptyset$\;
The second part:
\begin{algorithm}
\LinesNumbered
\setcounter{AlgoLine}{19}
%This is to hide Begin keyword
\SetKwBlock{Begin}{}{end}
\Begin{
Update the example code:
\documentclass{report}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\begin{document}
\begin{algorithm}
\LinesNumbered
% This is to hide end and get the last vertical line straight
\SetKwBlock{Begin}{Begin}{}
\SetAlgoLined
\Begin{
$\mathcal{E} \leftarrow \emptyset$;
}
\end{algorithm}
\SetNlSty{texttt}{(}{)}
\begin{algorithm}
\LinesNumbered
\setcounter{AlgoLine}{12}
% 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}
\Begin{
$\mathcal{E} \leftarrow \emptyset$;
$\mathcal{E} \leftarrow \emptyset$;
$\mathcal{E} \leftarrow \emptyset$;
$\mathcal{E} \leftarrow \emptyset$;
$\mathcal{E} \leftarrow \emptyset$;
}
\end{algorithm}
\end{document}
- 377
-
It sounds easy... how about providing an example that does this? The example should include nested blocks of pseudo-code and the algorithm broken across these nested blocks. – Werner Jan 10 '17 at 03:34
-
-
1How would you manage the case where there is a
\captionadded to the algorithm under theruledstyle? – Werner Jan 10 '17 at 03:56 -
Depends on what I want to achieve. Probably I don't see the problem. I would call parts like "Algorithm (Part 1 of 3)" etc... – outmind Jan 10 '17 at 16:54
-

algorithmicx(note the trailing “x”!) is far superior – Konrad Rudolph May 24 '11 at 14:00