4

I have a long algorithm that I would like to split in two pages. Something like this:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}  

\begin{document}

\begin{algorithm}
\caption{function}\label{function}
\begin{algorithmic}[1]
\Function{function}{}
    \State $x \gets y$;
    \While{$x < y$}
        \If{$x = y$}
            \State $split \gets split$; %%SPLIT HERE
        \ElsIf{$x = y$} 
            \State $x \gets y$;
        \ElsIf{$x < y$} 
            \State $x \gets y$;
            \State $x \gets y$;  
        \Else 
            \State $x \gets y$;
            \State $x \gets y$;
        \EndIf
    \EndWhile
    \If{$x = y$}
          \If{$x = y$}
              \State $x \gets y$;
          \ElsIf{$x = y$}
              \State $x \gets y$;
          \ElsIf{$x <= y$}
              \State $x \gets y$;
              \State $x \gets y$;
          \Else
              \State $x \gets y$;
              \State $x \gets y$;
          \EndIf
    \ElsIf{$x = y$}
        \State $x \gets y$;
    \EndIf
    \State \Return $x$
\EndFunction
\end{algorithmic}
\end{algorithm}

\end{document}

I found a solution using \algstore, however this does not work when placed in IF-ELSE structure. I have read something about \vsplit - but I am not sure how to use it to split my code.

1
  • Welcome to TeX.SE! Please add a MWE. Commented May 4, 2017 at 9:44

1 Answer 1

4

Don't use an algorithm environment:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}  

\begin{document}

\section{Function}\label{function}

\begin{algorithmic}[1] \Function{function}{}
    \State $x \gets y$;
    \While{$x < y$}
        \If{$x = y$}
            \State $split \gets split$; %%SPLIT HERE
        \ElsIf{$x = y$} 
            \State $x \gets y$;
        \ElsIf{$x < y$} 
            \State $x \gets y$;
            \State $x \gets y$;  
        \Else 
            \State $x \gets y$;
            \State $x \gets y$;
        \EndIf
    \EndWhile
    \While{$x < y$}
        \If{$x = y$}
            \State $split \gets split$; %%SPLIT HERE
        \ElsIf{$x = y$} 
            \State $x \gets y$;
        \ElsIf{$x < y$} 
            \State $x \gets y$;
            \State $x \gets y$;  
        \Else 
            \State $x \gets y$;
            \State $x \gets y$;
        \EndIf
    \EndWhile
    \While{$x < y$}
        \If{$x = y$}
            \State $split \gets split$; %%SPLIT HERE
        \ElsIf{$x = y$} 
            \State $x \gets y$;
        \ElsIf{$x < y$} 
            \State $x \gets y$;
            \State $x \gets y$;  
        \Else 
            \State $x \gets y$;
            \State $x \gets y$;
        \EndIf
    \EndWhile
    \While{$x < y$}
        \If{$x = y$}
            \State $split \gets split$; %%SPLIT HERE
        \ElsIf{$x = y$} 
            \State $x \gets y$;
        \ElsIf{$x < y$} 
            \State $x \gets y$;
            \State $x \gets y$;  
        \Else 
            \State $x \gets y$;
            \State $x \gets y$;
        \EndIf
    \EndWhile
    \If{$x = y$}
          \If{$x = y$}
              \State $x \gets y$;
          \ElsIf{$x = y$}
              \State $x \gets y$;
          \ElsIf{$x <= y$}
              \State $x \gets y$;
              \State $x \gets y$;
          \Else
              \State $x \gets y$;
              \State $x \gets y$;
          \EndIf
    \ElsIf{$x = y$}
        \State $x \gets y$;
    \EndIf
    \State \Return $x$
\EndFunction
\end{algorithmic}

\end{document}

enter image description here

1
  • May I ask, why do you say, "Don't use an algorithm environment"? Commented Jun 6, 2019 at 15:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.