算法包不会在页面太长时自动分页

算法包不会在页面太长时自动分页

我有一个用 algorithmc 定义的算法,如下所示:

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

假设这是一个非常长的算法。

有没有办法打破算法来适应许多页面?

答案1

您可以在合适的点手动中断算法\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}

对于自动分页符,不要将其包装在浮动环境中:

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

相关内容