带有分页符和换行符的排版算法

带有分页符和换行符的排版算法

我正在编写一个很长的算法,其中包含一些很长的行。Algorithm2e 不允许你将算法分成两页(algorithm2e 分为几页),并且 algorithicx 无法正确缩进长行(如何在算法中正确换行)。所以我根本无法使用第一个包,而对于第二个包,建议的解决方案是重新定义每个命令(\State、\If、\Else 等),以便它正确处理缩进。唯一的其他选择似乎是使用 algorithmicx 并手动处理换行符和缩进,这似乎与使用 TeX 等自动排版系统的观点完全相反。是否有任何包可以同时完成这两项工作,或者有任何合理的方法来解决这个问题?

编辑:这里有一个例子,显示 algorithmicx 不会换行:

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

编辑:这里有一个例子,显示如果算法太长,algorithm2e 不会将其分成两页:

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

相关内容