Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the algorithm2e package to put algorithm in my Latex documents.

In my document, I have something like this :

\section My algorithms
\subsection Algo 1
code for first algorithm
...


\subsection Algo 2
code for second algorithm
...

\subsection Algo 3
code for third algorithm
...

\subsection Algo 4
code for fourth algorithm
...

and so on.

The problem is that when producing the PDF, some algorithm are correctly displayed under their subsection, and some are displayed on other pages, not under the right section.

I get something like this :

1. My algorithms
1.1 Algo 1
    pseudo code for algo 1

1.2 Algo 2
    pseudo code for algo 2

1.3 Algo 3
1.4 Algo 4
---------------- next page -----------
    pseudo code for algo 3
---------------- next page -----------
    pseudo code for algo 4

Here is the full Latex source code : http://www.filedropper.com/demo_1 Here is the PDF I get : http://www.filedropper.com/demo_2

Is there a way to make sure the algo will stick with its subsection ?

share|improve this question

migrated from stackoverflow.com Sep 8 '12 at 22:06

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer 1

up vote 10 down vote accepted

algorithm is a floating environment, just like figure or table. Quoth the manual:

The optional arguments [Hhtbp] [to the algorithm environment, U.S.] works like those of figure environment. The H argument forces the algorithm to stay in place. If used, an algorithm is no more a floating object. Caution: algorithms cannot be cut, so if there is not enough place to put an algorithm with H option at a given spot, LATEX will place a blank and put the algorithm on the following page.

share|improve this answer
    
I feel so silly I didn't spot that ! Thanks ! –  Jérôme Feb 11 '11 at 8:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.