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 typesetting an algorithm using the algorithmx package as follows:


However, I would like it to float like a figure. If I replace \begin{algorithm} with \begin{figure} it does float as I like, however, the caption does not look as pretty any more (I presume it is redefined by a sig-alternate class I am using for the whole document).

Is it possible to have both a nice caption and floating behaviour at the same time?

share|improve this question
Have you looked into using the float package? – Harald Hanche-Olsen Nov 29 '10 at 14:18
Yes, thank you, it does work. I'll put this as an answer. – Konstantin Nov 29 '10 at 15:11
up vote 20 down vote accepted

Thanks to Harald's advice I found the following two-line solution to my problem:


This was sufficient to make all my algorithm blocks to float exactly as I needed them to.

See also: "float" package reference.

share|improve this answer
Add \floatname{algorithm}{Algorithm} to capitalise the float name. – badroit Nov 11 '13 at 5:19

The LaTeX Wikibook section on algorithms explains this very nicely:

The algorithmicx package provides a number of popular constructs for algorithm designs. Put \usepackage{algpseudocode} in the preamble to use the algorithmic environment to write algorithm pseudocode (\begin{algorithmic}...\end{algorithmic}). You might want to use the algorithm environment (\usepackage{algorithm}) to wrap your algorithmic code in an algorithm environment (\begin{algorithm}...\end{algorithm}) to produce a floating environment with numbered algorithms.

Meaning, you only need to add \usepackage{algorithm} and your code snippet will be rendered as a floating figure.

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.