[Tex/LaTex] How to very long algorithms be automatically split over multiple pages

algorithmicalgorithmsformatting

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.

Best Answer

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

enter image description here

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