This is a follow-up question to Option in the algorithm with Latex.

This is the code:

  \caption{My algorithme}
    \Donnees: My data
    \Statex% Blank line
      \LState $r\gets a\bmod b$
      \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \LState $a\gets b$
        \LState $b\gets r$
        \LState $r\gets a\bmod b$
        \If {condition}
          \LState instruction

  \caption{\textit{second Part}
      \LState \textbf{Retour} $b$\Comment{The gcd is b}


When I try to divide this algorithm inside the if--else with \algrestore{testcont} it does not work! Have you an idea please?

  • Actually, I do not understand the question. What code does work and what code does not? What would be the desired output? Dec 4, 2015 at 14:32

1 Answer 1


Instead of relying on the \algsave-\algrestore method of breaking an algorithm, we can break it using the "page-breaking algorithm" via \vsplit. Quoting from TeX by Topic (section 27.5 \vsplit, p 230):

The page-breaking operation is available to the user through the \vsplit operation.

\setbox1 = \vsplit2 to \dimen3

assigns to box 1 the top part of size \dimen3 of box 2. This material is actually removed from box 2.

We set the algorithm outside the algorithm float in \algbox (a box register) and then split it into \algboxtop (which contains the top 10 baselines) and the remainder in \algbox (whatever is left).

Additionally, in order to allow for a "continued" caption, we can use \caption* (provided by caption) together with some cross-referencing.

enter image description here


\renewcommand{\ALG@name}{Algorithme}% Algorithm in French
\algnewcommand{\Debut}{\Statex \textbf{D\'ebut}\pushindent}
\algnewcommand{\Fin}{\Statex \textbf{Fin}\popindent}

% This is the vertical rule that is inserted
\def\therule{\makebox[\algorithmicindent][l]{\hspace*{.5em}\vrule height .75\baselineskip depth .25\baselineskip}}%

\newtoks\therules% Contains rules
\therules={}% Start with empty token list
\def\appendto#1#2{\expandafter#1\expandafter{\the#1#2}}% Append to token list
\def\gobblefirst#1{% Remove (first) from token list
\def\LState{\State\unskip\the\therules}% New line-state

%      ***      DECLARED LOOPS      ***
% (from algpseudocode.sty)
  {\printandpush\textbf{Tant que} #1}
  {\popandprint\textbf{Fin Tant que}}%
  {\printandpush\algorithmicfor\ #1\ \algorithmicdo}
  {\popandprint\algorithmicend\ \algorithmicfor}%
  {\printindent\algorithmicforall\ #1\ \algorithmicdo}%
  {\popandprint\algorithmicend\ \algorithmicloop}%
  {\popandprint\algorithmicuntil\ #1}%
  {\printandpush\algorithmicif\ #1\ \algorithmicthen}
  {\popandprint\algorithmicend\ \algorithmicif}%
  {\popandprint\pushindent\algorithmicelse\ \algorithmicif\ #1\ \algorithmicthen}%
   {\printandpush\algorithmicprocedure\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\popandprint\algorithmicend\ \algorithmicprocedure}%
   {\printandpush\algorithmicfunction\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\popandprint\algorithmicend\ \algorithmicfunction}%
\newcommand{\Donnees}{\State \textbf{Input}}



  \Donnees\strut: My data
  \Statex% Blank line
    \LState $r \gets a \bmod b$
    \While{$r \neq 0$}\Comment{We have the answer if~$r$ is~$0$}
      \LState $a \gets b$
      \LState $b \gets r$
      \LState $r \gets a \bmod b$
      \If {condition}
        \LState instruction
    \LState \textbf{Retour} $b$\Comment{The gcd is $b$}
% Break algorithm into 2 parts: Top in \algoboxtop, bottom in \algbox
\global\setbox\algboxtop = \vsplit\algbox to 10\baselineskip%

  \caption{My algorithme}\label{alg:first}
  % Capture entire algorithm inside \algbox (a \vbox)
  \usebox{\algboxtop}% Set top box

  % http://tex.stackexchange.com/a/33076/5764
  \caption*{\textbf{\algorithmname~\ref{alg:first}}\ My algorithme (continued)}


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .