16

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?

Martin Scharrer
  • 262,582
kunigami
  • 261

3 Answers3

4

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

Martin Scharrer
  • 262,582
Bruno
  • 2,060
4

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}

enter image description here

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

2nd: Remove the rule below the algorithm title - using Algorithm2e

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

Mori
  • 43
1

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

by using: \footnotsize or \scriptsize.

and it worked just fine.

xmen-5
  • 175
  • Well, it is not consistent anymore. –  May 17 '19 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. – xmen-5 May 17 '19 at 22:23