GeneralHow to add headings for splitted algorithms

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
daiyue
Posts: 17
Joined: Mon May 21, 2012 5:58 pm

How to add headings for splitted algorithms

Post by daiyue »

Hi, after I splitted a long algorithm into 2-3 parts across 3 pages. I now add a caption like "Algorithm 1 continued" to each of the consecutive part.

Code: Select all

\begin{algorithm}
\caption{Construct relational tables}
\label{alg3}
\begin{algorithmic}[1]
\Input a set of data item clusters $C$
\Output a relational table with all data items aligned
\State some algorithm code
\State ...
\algstore{myalg}
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{Algorithm \ref{alg3} continued}
\begin{algorithmic} [1]                   % enter the algorithmic environment
\algrestore{myalg}
\State some other algorithm code
\State ...
\end{algorithmic}
\end{algorithm}
The problem is
caption for splitted the algorithm
caption for splitted the algorithm
splitted algorithm caption.PNG (21.92 KiB) Viewed 7671 times
As shown, each splitted part's caption is shown as a separated algorithm, but it is incorrect. So how to resolve the issue.
thanks
Last edited by daiyue on Sun Aug 16, 2015 11:15 pm, edited 3 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: How to add headings for splitted algorithms

Post by Johannes_B »

How did you generate the splitted algorithm? Can you show us a minimal working example?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
daiyue
Posts: 17
Joined: Mon May 21, 2012 5:58 pm

How to add headings for splitted algorithms

Post by daiyue »

Johannes_B wrote:How did you generate the splitted algorithm? Can you show us a minimal working example?
I have modified my OP.

thanks
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to add headings for splitted algorithms

Post by Stefan Kottwitz »

You could use \algstore{somename} at the and of a part, and \algrestore{somename} at the beginning of the next part. Each part would be like a normal algorithm environment with a caption. You can use the same \caption or different captions in each part.

If you would show code, we can take it as example. No problem to read a long algorithm here. :-)

Stefan

edit: posted before the OP was updated with the mentioned commands shown.
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to add headings for splitted algorithms

Post by Stefan Kottwitz »

daiyue wrote:I have modified my OP.
That's nice, but it would be really great if you would make it compilable. Without, nobody here can execute it. Don't worry about the space in the forum, no problem at all. Making it easy to test ensures quick and good answers which have been tested.

Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to add headings for splitted algorithms

Post by Stefan Kottwitz »

Idea: use the caption package in the preamble:

Code: Select all

\usepackage{caption}
and then in the 2nd and 3rd algorithm parts the starred version:

Code: Select all

\caption*{Algorithm \ref{alg3} continued}
This way you won't get a caption starting with "Algorithm 4:" or the like.

Stefan
LaTeX.org admin
Post Reply