[Tex/LaTex] Algorithm over 2 pages

algorithmsfloatspage-breaking

I am writing a few rather large pseudocode functions using algorithm and algorithmic, i.e. my code looks something like:

\begin{algorithm}                     
\caption{Coolest Algorithm ever}          
\label{findme}                          
\begin{algorithmic} [1]                   % enter the algorithmic environment
\REQUIRE    Here are a few variables \\
            variable 2 \\
            variable 3 
\ENSURE     this is the output \\
            output 2

\STATE $some cool code here$
\STATE $some cool code here$
\STATE $some cool code here$
\STATE $some cool code here$
\end{algorithmic}
\end{algorithm}

Unfortunately this code does not fit on one page and I am definitely not able to split it into some subfunctions or so (I already did that as far as possible).

So now I need to split up the algorithm into two pages, but I have no idea how.

The easiest way I can imagine is just to start a new algorithm on the new page, but this time letting the line counter start at line 35 or so instead of 1. But how can I do that?

Please not that there is already a similar question here on this site, but it deals with the package algorithmicx.

Best Answer

You should use the algorithmicx package instead and its \algstore and \algrestore commands. If you don't want to rewrite all your algorithmic algorithms, you can still use algorithmicx either by loading the algpseudocode package with the compatible option, or by loading the algcompatible package:

\documentclass{article}
\usepackage{algcompatible}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}                     
\caption{Coolest Algorithm ever}          
\label{findme}                          
\begin{algorithmic} [1]                   % enter the algorithmic environment
\REQUIRE    Here are a few variables \\
            variable 2 \\
            variable 3 
\ENSURE     this is the output \\
            output 2
\algstore{myalg}
\end{algorithmic}
\end{algorithm}

\begin{algorithm}                     
\begin{algorithmic} [1]                   % enter the algorithmic environment
\algrestore{myalg}
\STATE $some cool code here$
\STATE $some cool code here$
\STATE $some cool code here$
\STATE $some cool code here$
\end{algorithmic}
\end{algorithm}

\end{document}

Example output for algorithm over 2 pages

Related Question