TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 down vote accepted

algorithm2e makes floats for algorithms. You can use


for non-float algorithms. This is illustrated at the beginning of the package manual.

share|improve this answer

Your Answer


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.