1

I am writing a long algorithm with some long lines in it. Algorithm2e does not allow you to break an algorithm across two pages (algorithm2e split over several pages), and algorithicx does not correctly indent long lines (How to wrap lines correctly inside algorithmic). So I simply cannot use the first package, and for the second package the proposed to solution is to redefine every single command (\State, \If, \Else etc.) so that it correctly handles indentation. The only other option would seem to be using algorithmicx and handling line breaks and indentation manually, which seems completely contrary to the point of using an automated typesetting system like TeX. Is there any package which does both, or any reasonable way of solving this problem?

Edit: Here is an example showing that algorithmicx won't wrap lines:

\documentclass[11pt, oneside]{article}      % use "amsart" instead of "article" for AMSLaTeX format
\usepackage{geometry}
\usepackage{algorithm}
\usepackage{algpseudocode} % algpseudocode from algorithmicx
\geometry{letterpaper}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{parskip}

\begin{document}

\subsection{Pseudocode}
\begin{algorithm}[H]
\begin{algorithmic}
    \Function{fastestSplitOrder}{splitPersonList, lineLength}
        \State Let something equal something
        \State Do some other stuff
        \If{this is true}
            \State do this stuff
            \If{this is true}
                \State do this stuff
                \If{this is true}
                    \State do this stuff
                    \If{this is true}
                        \State do this stuff
                        \State This is a really loooooooooooooooooooooooooooooooooog liiiiiiiiiiiiiiiiiiiiiine where we say a bunch of stuff, because this is pseudocode and we like to say things in english sometimes so that they are easy to understand instead of overcomplicating the pseudocode and making it like implemented code instead, but things can take more than a line of words to explain
                    \EndIf
                \EndIf
            \EndIf
        \EndIf

    \EndFunction
\end{algorithmic}
\end{algorithm}

\end{document}

Edit: Here is an example showing that algorithm2e will not split an algorithm over two pages if it is too long:

\documentclass[11pt, oneside]{article}      % use "amsart" instead of "article" for AMSLaTeX format
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{algorithm2e}
\geometry{letterpaper}

\begin{document}

\subsection{Pseudocode}
\begin{algorithm}[H]
\SetKwFunction{fastestSplitOrder}{fastestSplitOrder}
\SetKwProg{Fn}{Function}{}{}
\Fn{\fastestSplitOrder{splitPersonList, lineLength}}{
    This is a veeeeeeeeeeeeeeeeery looooooooooooooooooooooooong liiiiiiiiiiiiiiiiiiiiiiiine thaaaaaaaaaaaaaaaaaaaaaaaaaat wiiiiiiiiiiiilllllllllllll wrap\\
    \For{size = 1 through size = k +1}{
        \If{thing}{
            do some stuff
            \If{thing}{
                do some stuff
                \If{thing}{
                    do some stuff
                    \If{thing}{
                        do some stuff
                        \If{thing}{
                            do some stuff
                            \If{thing}{
                                do some stuff
                                \If{thing}{
                                    do some stuff
                                    \If{thing}{
                                        do some stuff
                                        \If{thing}{
                                            do some stuff
                                            another line
                                            another line
                                            another line
                                            another line
                                            another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        aanother line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        another line
                                        nother line

                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
    \Return ORDER[0,k+1]\\
}
\end{algorithm}

\end{document}
  • 1
    There must be... can you provide us the foundation to work from in the form of a minimal example? – Werner Nov 2 '16 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.