Document ClassesAlgorithms over several pages

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
bsamuel
Posts: 1
Joined: Mon Jan 14, 2008 11:15 pm

Algorithms over several pages

Post by bsamuel »

Hi there,

I'm using the algorithms package to display pseudocode. I put an algorithmic environment inside an algorithm environment, which numbers the different algorithms nicely and makes them show up in a list of algorihms in the beginning (analogous to a list of figures/tables). However, it also turns the algorithm into a floating object and this seems to prevent Latex from introducing page breaks.

I now have an algorithm that is more than one page long. What Latex does is the following: It just continues the text on one page until it leaves the page at the bottom and disappears into nirvana.

Any ideas what I should do to have Latex introduce page breaks where necessary? Or is there a way to force them myself?

Thanks a lot!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: Algorithms over several pages

Post by balf »

The algorithmicx package might do what you want: you can breal algorithms in several parts (e.g. to insert comments) while retaining the numbering of lines. You should take a look at it. Of course each time it would be a sort of manual work, but do you need to do it that often?

Regards,
B.A.
amegahed3
Posts: 15
Joined: Wed Feb 25, 2009 11:20 am

Re: Algorithms over several pages

Post by amegahed3 »

I face the EXACT same problem, and very frequently (since I am writing a lot of algorithms).

Any ideas about a good way (preferably automatic) to do so? Especially that my algorithms are inside a document, and I do insert and delete text from the document so often, so a manual way to handle that problem with algorithms will be very hectic!
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Algorithms over several pages

Post by localghost »

Did you already take a look at the algorithmicx package like balf suggested? Alternative packages for code output are
Study the according manuals to learn more about the packages.


Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
francos3
Posts: 1
Joined: Fri Apr 09, 2010 4:35 pm

Algorithms over several pages

Post by francos3 »

Hi,
I had the same problem. As the manual states:
4.1 General
When placed within the text without being encapsulated in a floating environment
algorithmic environments may be split over a page boundary, greatly
detracting from their appearance.
2 In addition, it is useful to have algorithms
numbered for reference and for lists of algorithms to be appended to the list
of contents. The algorithm environment is meant to address these concerns by
providing a floating environment for algorithms.
So yes you can but not as a float Algorithm package. You need to use the algorithmic environment. But as some other people suggested, do you really need several pages to describe pseudocode? Maybe it is a good idea to abstract away some tasks as secondary algorithms. That is what I did at the end and it was much easier to follow. Also if you use the algorithmic environment you will loose the ability to number them and display them in the list of contents.

Cheers
ThoughtSearcher
Posts: 1
Joined: Fri Jan 14, 2011 7:12 pm

Re: Algorithms over several pages

Post by ThoughtSearcher »

You can do this in 'algorithm' environment too!

1. Use \algstore{some_name} as the last command of your algorithm block (the line after which you want to split the algorithm)

2. Use \algrestore{some_name} as the first command of new algorithm block. Paste your remaining code below this command in this new algorithm block.

Make sure you use the same name in \algstore and \algrestore.
Post Reply