Sign up ×
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 would like to present an algorithm in my article. For that I am using the algorithm2e package (and I have used it for many years).

I want to use the ruled option, i.e., I load the package like this:


Unfortunately, with the ruled option, the algorithm2e package puts the caption above the pseudo code.

However, I want the caption to appear underneath the pseudo-code, just like any other caption in figures or tables.

Does anybody know, what I need to change in the style file to make this possible? Or can I achieve it with the help of the float package? (Note that I still would like to have a kind of algorithmic environment like this

\caption{An algorithm}

) I am using the latest version, i.e., 4.01, of algorithm2e.sty.

share|improve this question
-1 -- same question at c.t.t.:… – Marco Daniel Sep 6 '11 at 15:47
Thanks for asking the question. In my document, the default setting put the caption below the algorithm which I didn;t like. After seeing this post i realized that using the 'ruled' option would put the caption above the algorithm. – A. K. Aug 5 '12 at 18:31

1 Answer 1

up vote 5 down vote accepted

You can achieve this by defining a new environment which puts the caption under instead of the default top, and adjusting the vertical skip between a rule and the caption text:


  {\def\@algocf@post@ruled{\kern\interspacealgoruled\hrule  height\algoheightrule\kern3pt\relax}%


\If{$i<5$}{some action}
\caption{A ruled algorithm with caption above}

\If{$i<5$}{some action}
\caption{A ruled algorithm with caption below}


enter image description here

share|improve this answer
@Gabriel: That should be easy to fix: Modify \newenvironment{Ualgorithm}[1][h]...\begin{algorithm}[#1]. This will make the default float placement h, unless otherwise specified using (say) \begin{Ualgorithm}[tb]...\end{Ualgorithm}. – Werner Sep 6 '11 at 17:28
@Werner: I added the optional argument; however, some tests I did, showed that it was not really necessary. The environment, as it was, behaved like a float. Perhaps I didn't do enough tests...? – Gonzalo Medina Sep 6 '11 at 17:38
algorithm2e.sty defines the algocf[*] environment as \newenvironment{algocf}{\@float{algocf}}{\end@float} which may have a default that doesn't correspond to the OP's taste. The testing is subjective, of course, since you don't have a document resembling the OP's setup. – Werner Sep 6 '11 at 17:45
LaTeX issues a warning if the optional parameter to Ualgorithm is empty, substituting it to the default htbp. Perhaps specify this as the default [htbp] to avoid this warning. – Werner Sep 6 '11 at 17:48
@Werner: yes, but what I meant (perhaps I wasn't clear) is that the Ualgorithm environment (as it was initially defined without the optional argument) would receive (and obey) the optional argument for placement specifiers. – Gonzalo Medina Sep 6 '11 at 17:48

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.