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
add comment

1 Answer

up vote 3 down vote accepted

algorithm2e makes floats for algorithms. You can use

\begin{algorithm}[H]
...

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

share|improve this answer
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.