1

This question already has an answer here:

I have an algorithm defined with algorithmc like this:

    \documentclass{article}
    \usepackage{algorithm}
    \usepackage{algorithmicx}

    \begin{document}

    \begin{algorithm}
    \begin{algorithmic}[1]
    \Function{X}{ItemA, ItemB, ItemC}
    \State {Lorem Lorem}
    \State {Final}
    \end{algorithmic}
    \end{algorithm}


    \end{document}

Suppose that this is a very long algorithm.

Is there a way to break algorithm to fit in many pages?

marked as duplicate by Werner, Phelype Oleinik, Stefan Pinnow, siracusa, Marijn Jun 26 at 21:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You can manually break the algo at a suitable point with \algstore{bkbreak}...\algrestore{bkbreak}:

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmicx}

\begin{document}

\begin{algorithm}
\begin{algorithmic}[1]
\State {em Lorem}
(...)
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\algstore{bkbreak}
\end{algorithmic}
\end{algorithm}


\begin{algorithm}
\begin{algorithmic}[1]
\algrestore{bkbreak}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\end{algorithmic}
\end{algorithm}

\end{document}

For automatic page breaks, don't wrap it in a floating environment:

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmicx}

\begin{document}

%\begin{algorithm}
\begin{algorithmic}[1]
\State {em Lorem}
(...)
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\State {Final}
\end{algorithmic}
%\end{algorithm}

\end{document}
  • Thanks. This works, but any chance of doing this automatically? – Bruno Camarda Jun 26 at 20:05
  • Thanks a lot @Pizzagne, this works perfectly – Bruno Camarda Jun 26 at 20:22

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