# How can very long algorithms be automatically split over multiple pages?

I have a very long algorithm than spans several pages. I can not get Latex to make it span across several pages. I know that several questions similar to this one have already been asked, but I haven't been able to find the answer I'm looking for in any of them.

My algorithm comprises several steps, each described in an algorithmic environment, and all those steps are nested together in an algorithm environment, as shown in the MWE below:

\begin{algorithm*}[!h]
\caption*{\textbf{Algorithm}}
\textbf{1)} Step 1
\begin{algorithmic}[1]
\State \textit{code}
\State \textit{pseudo code
\begin{itemize}
\item{item 1}
\item{Item 2}
\end{itemize}
\end{algorithmic}

\textbf{2)} Step 2

\begin{algorithmic}[1]
\State \textit{code}
\State \textit{code}
\end{algorithmic}

\textbf{3)} Step 3
\begin{algorithmic}
...
\end{algorithmic}

\end{algorithm*}


I have quite a lot of algorithms all inside a long document and I often have to make changes to the document (by inserting & deleting text, figures, ...) so I'm looking for an automatic way for Latex to split the algorithm over multiple pages, that enables me to present my algorithms in multiple steps as shown in the MWE above.

Any help very welcome.

-
Just remove the {algorithm*} environment which is a floating box, and boxes never break, the algorithmic environment breaks over pages. (Never use [h!] fro any float, either don't use the option or use [htbp] as disallowing t and p floats makes it very likely the float goes to end of document) – David Carlisle Apr 13 '13 at 22:16

## 1 Answer

It looks from your \State command that you are using the package algorithmicx as algorithmic defines \STATE

\documentclass{article}
\usepackage{algorithmicx}

\addtolength\textheight{-32\baselineskip}
\addtolength\paperheight{-32\baselineskip}
\pdfpageheight\paperheight
\renewcommand\labelenumi{\textbf{\theenumi) }}
\begin{document}

\subsection*{Algorithm}

\begin{enumerate}
\item  Step aaa
\begin{algorithmic}[1]
\State \textit{code}
\State \textit{pseudo code}
\begin{itemize}
\item{item 1}
\item{Item 2}
\end{itemize}
\State \textit{pseudo code}
\begin{itemize}
\item{item 1}
\item{Item 2}
\end{itemize}
\end{algorithmic}

\item Step bbb

\begin{algorithmic}[1]
\State \textit{code}
\State \textit{code}
\State \textit{code}
\State \textit{code}
\State \textit{code}
\end{algorithmic}

\item Step ccc
\begin{algorithmic}
\State \textit{code}
\end{algorithmic}
\end{enumerate}

\end{document}

-
This worked for me, thanks! – Percy Apr 14 '13 at 11:16