Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

1 Answer

up vote 4 down vote accepted

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}
share|improve this answer
    
This worked for me, thanks! –  Percy Apr 14 '13 at 11:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.