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

During the IEEEtrans.tex, there is a comment below package algorithmic saying that

Do NOT use the algorithm floating environment provided by algorithm.sty (by the same authors) or algorithm2e.sty (by Christophe Fiorio) as IEEE does not use dedicated algorithm float types and packages that provide these will not provide correct IEEE style captions.

How can I make a beautiful box to show the pseudo code while using only the algorithmic package?

share|improve this question
You can download the algorithmic package from here: ctan.org/tex-archive/macros/latex/contrib/algorithms It contains a .pdf with instructions on how to do what you are looking for. – latex fan Jun 22 '12 at 0:03
up vote 12 down vote accepted

You can try something like this:




\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$


enter image description here

share|improve this answer
Many thanks for sharing! I still have a problem about the caption. Which part should I modify if I want to reference this box? Could I write the box part into a Table? – datcn Jan 6 '12 at 13:05
Update: I find the way of adding the title and caption. Move the box part into a '\begin{table}' and '\end{table}' is OK. Thanks again for your help. – datcn Jan 6 '12 at 13:20

Instead of Table, you can use a Figure, in which you can add caption and label.

\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$
\STATE $y \leftarrow 1$
\IF{$n < 0$}
\STATE $X \leftarrow 1 / x$
\STATE $N \leftarrow -n$
\STATE $X \leftarrow x$
\STATE $N \leftarrow n$
\WHILE{$N \neq 0$}
\IF{$N$ is even}
\STATE $X \leftarrow X \times X$
\STATE $N \leftarrow N / 2$
\ELSE[$N$ is odd]
\STATE $y \leftarrow y \times X$
\STATE $N \leftarrow N - 1$
\caption{My algorithm}
share|improve this answer
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – doncherry Jun 22 '12 at 15:59

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.