0

This is a follow-up question to: https://tex.stackexchange.com/a/33869/173478

The breakablealgorithm environment, as proposed by Werner, splits algorithms perfectly. However, for me the breakable algorithms have different vertical padding from the regular algorithms. The following is a minimal example for reproducing the behavior:

\documentclass[a4paper]{article}
\usepackage{algorithm,algpseudocode}

\makeatletter
\newenvironment{breakablealgorithm}
  {% \begin{breakablealgorithm}
   \begin{center}
     \refstepcounter{algorithm}% New algorithm
     \hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
     \renewcommand{\caption}[2][\relax]{% Make a new \caption
       {\raggedright\textbf{\fname@algorithm~\thealgorithm} ##2\par}%
       \ifx\relax##1\relax % #1 is \relax
         \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
       \else % #1 is not \relax
         \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
       \fi
       \kern2pt\hrule\kern2pt
     }
  }{% \end{breakablealgorithm}
     \kern2pt\hrule\relax% \@fs@post for \@fs@ruled
   \end{center}
  }
\makeatother

% DOCUMENT

\begin{document}

This is some text.
\begin{algorithm}[H]
  \caption{Regular Algorithm}
  \begin{algorithmic}
    \State Start
  \end{algorithmic}
\end{algorithm}
And some more text.
\begin{breakablealgorithm}
  \caption{Breakable Algorithm}
  \begin{algorithmic}
    \State Start
  \end{algorithmic}
\end{breakablealgorithm}
And even more text.

\end{document}

enter image description here

Also, when setting the document class to amsart or amsbook, there is no padding at all. How can I modify the breakablealgorithm environment to naturally have the same padding as the regular algorithm environment?

1 Answer 1

1

It seems the algorithm environment is using the \intextsep quantity for vertical padding. The breakablealgorithm environment can therefore be modified to always have the same padding as the algorithm environment by replacing the center environment with the appropriate vertical spacing:

\makeatletter
\newenvironment{breakablealgorithm}
  {% \begin{breakablealgorithm}
    \par\vspace{\intextsep}
      \refstepcounter{algorithm}% New algorithm
      \hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
      \renewcommand{\caption}[2][\relax]{% Make a new \caption
        {\raggedright\textbf{\fname@algorithm~\thealgorithm} ##2\par}%
        \ifx\relax##1\relax % #1 is \relax
          \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
        \else % #1 is not \relax
          \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
        \fi
        \kern2pt\hrule\kern2pt
     }
  }{% \end{breakablealgorithm}
      \kern2pt\hrule\relax% \@fs@post for \@fs@ruled
    \par\vspace{\intextsep}
  }
\makeatother

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.