Here's one possible solution; it requires for you to issue \BreakAlgo
before an algorithmth that will have the new specifications:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algcompatible}
\usepackage{etoolbox}
\makeatletter
\newcommand\fs@myruledtop{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
\def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
\def\@fs@post{\kern2pt}%
\def\@fs@mid{\kern2pt\hrule\kern2pt}%
\let\@fs@iftopcapt\iftrue}
\newcommand\fs@myruledbottom{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
\def\@fs@pre{\kern2pt}%
\def\@fs@post{\kern2pt\hrule\relax}%
\def\@fs@mid{}%
\let\@fs@iftopcapt\iftrue}
\makeatother
\newif\ifalgobreak
\newif\ifalgobreaksecond
\newcommand\BreakAlgo{\algobreaktrue}
\AtBeginEnvironment{algorithm}{
\ifalgobreak
\floatstyle{myruledtop}
\restylefloat{algorithm}
\fi
\ifalgobreaksecond
\floatstyle{myruledbottom}
\restylefloat{algorithm}
\else
\fi
}
\AfterEndEnvironment{algorithm}{%
\algobreakfalse\algobreaksecondfalse
\floatstyle{ruled}
\restylefloat{algorithm}%
}
\newcommand\algoallowbreak[1][]{%
\algstore{myalg}
\end{algorithmic}
\end{algorithm}
\algobreaksecondtrue
\begin{algorithm}
\begin{algorithmic}[#1]
\algrestore{myalg}%
}
\begin{document}
\BreakAlgo
\begin{algorithm}[h]
\caption{Algorithm 1}
\begin{algorithmic}[1]
\State $a \gets b$
\State some other code
\algoallowbreak
\State some code that could possibly be wrap onto the next side
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[h]
\caption{Algorithm 2}
\begin{algorithmic}[1]
\State $a \gets b$
\State some other code
\end{algorithmic}
\end{algorithm}
\end{document}
The idea was to define two new styles for algorithms (one suppressing the bottom rule, the other one, suppressing the top rule) and applying these new styles conditionally depending on \BreakAlgo
I also added an optional argument to \algoallowbreak
so as to specify numbering in the continuation part; notice that this fixes the alignment problem you had in your original settings for the continuation. If the numbering will always be present, you don't need the optional argument and in this case the definition would be
\newcommand\algoallowbreak{%
\algstore{myalg}
\end{algorithmic}
\end{algorithm}
\algobreaksecondtrue
\begin{algorithm}
\begin{algorithmic}[1]
\algrestore{myalg}%
}
And then, in your document:
\BreakAlgo
\begin{algorithm}[h]
\caption{Algorithm 1}
\begin{algorithmic}[1]
\State $a \gets b$
\State some other code
\algoallowbreak
\State some code that could possibly be wrap onto the next side
\end{algorithmic}
\end{algorithm}
The algorithm
bundle defines the algorithm
environment/float using the float
package. As such, you can restyle it using its tools.
You can define an new float style, say nobottomruled
, which removes the "post" (rule) construction:
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\makeatletter
\newcommand\fs@nobottomruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
\def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
\def\@fs@post{}% Formerly \def\@fs@post{\kern2pt\hrule\relax}%
\def\@fs@mid{\kern2pt\hrule\kern2pt}%
\let\@fs@iftopcapt\iftrue}
\makeatother
\floatstyle{nobottomruled}
\restylefloat{algorithm}
\begin{document}
\begin{algorithm}[H]
\caption{foo}
\begin{algorithmic}[1]
\State bar
\end{algorithmic}
\end{algorithm}
\end{document}
Best Answer
If you are using the
algorithm
package, it is enough to use theplain
option: