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.

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 would like to put one algorithm inside one enumerated list like in the following code.




    \item Bla, bla...

    \caption{Le crible d'Eratosthène}

    \KwData{la liste $L$ des naturels compris de $2$ à $N$.}
    \KwResult{la liste $P$ des nombres premiers compris entre $2$ et $N$.}
    \For{$i = 2$ \KwTo $N$}{
        \If{$i$ n'est pas barré dans la liste $L$}{
            Barrer dans la liste $L$ les mutltiples $ki$ où $k \geq 2$.
    \Return{la liste $P$ des nombres non barrés.}

    \item Bla, bla...


The problem I met is that I obtain the following output where the algorithm is misplaced (or too width).

enter image description here

If someone can give one solution with the algorithm centered regarding to the page, and not to the item content, it would be great.

share|improve this question
up vote 2 down vote accepted

The main problem is that algorithm2e uses \hsize in its macros, which is not recommended.

You can probably solve the issue by saying


but I can't guarantee that this has no side effects.

enter image description here

Alternative way, using the full line width: define an listalgorithm environment to be used inside lists


enter image description here

Final comment. I would avoid with all my strengths to place an algorithm inside an enumerate or itemize environment.

share|improve this answer
Thanks for the proposition. Indeed this is for at 15 to 18 years old students, so I prefer to use this not so good formatting for algorithms. – projetmbc Oct 11 '12 at 15:32

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.