# How to split algorithm2e over two pages

I'm using algorithm2e package but my algorithm does not fit in only one page. Is there any way to split it over two pages, even if manually?

If doing it manually, we can use two algorithm environments, but there are some issues:

1. Maintain the line counting - OK, this can be done by calling the package with noresetcount

2. Remove the caption from the first/second algorithm (depending if we want the caption in the beginning or end) -- how to do it?

3. Take care of the vertical lines of the indentation, that is, I expect them to "cross" the pages -- how to do it?

If you don't have to use algorithm2e, you should have a look at the listings package, which supports listings on multiple pages.

There is a trick that I follow the answer for algorithm2e split over several pages by outmind

\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}
% 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}


For line numbering you can use \usepackage[ruled,vlined]{algorithm2e} instead of \usepackage[linesnumbered,ruled,vlined]{algorithm2e} and number the lines by using \nl. Or you can use \LinesNotNumbered{ before begin{algorithm} To remove the rule line : there are three ways: first, using

\setlength{\algoheightrule}{0.8pt} % thickness of the rules above and below
\setlength{\algotitleheightrule}{0pt} % thicknes of the rule below the title


3rd: good way, top, bottom, middle line colored by using Colored horizontal lines in algorithm2e by Werner

For me i solved this problem by reducing the size of the text.

by using: \footnotsize or \scriptsize.

and it worked just fine.

• Well, it is not consistent anymore. – user156344 May 17 at 14:10
• I agree but sometimes it solve the problem without needing to spilt the algo. unfortunatly as i m using algorithm2e packege i coudn't found an easy solution to that problem. – zak zak May 17 at 22:23