# Why does LaTeX mix up the order of my algorithms and other output? [duplicate]

Possible Duplicate:
How to avoid splitting tables between sections

I did something like this:

\documentclass{article}

\usepackage[T1]{fontenc}

\usepackage{algorithm}

\usepackage{algorithmic}

\usepackage{array}

\usepackage{eqparbox}

\usepackage[pdftex]{graphicx}

\begin{document}
\begin{algorithm}

\begin{algorithmic}

algorithm goes here

\end{algorithmic}

\end{algorithm}

\begin{algorithm}

\begin{algorithmic}

algorithm goes here

\end{algorithmic}

\end{algorithm}

\section{test}

section contents.

\end{document}


When I render the PDF, the test section appears before the second algorithm, instead of after it. Isn't LaTeX supposed to render them in the above order?

-

## migrated from stackoverflow.comNov 5 '11 at 21:09

This question came from our site for professional and enthusiast programmers.

## marked as duplicate by lockstep, cmhughes, Jake, Torbjørn T., Stefan Kottwitz♦Nov 6 '11 at 11:54

Also, which package are you using here? Neither the environment algorithm nor algorithmic is part of the LaTeX kernel or the standard classes. Please edit your question to add a complete example there (including the preamble), this spares us guessing the packages your are using. –  Paŭlo Ebermann Nov 5 '11 at 20:41
@mak89k: The algorithm environment is a "floating" environment. The answers in the linked question about tables also apply to algorithms. –  lockstep Nov 5 '11 at 21:27
Algorithm is a floating environment. So, you need to put a [!h] next to it if you want it to appear exactly where you're putting it. Like so:
\begin{algorithm}[!h]

[!h] is not enough so avoid floating. It reduces floating only. To avoid floating don't use floats and to avoid floating after a section use placeins. See the link at lockstep's comment above for more information. –  Schweinebacke Nov 6 '11 at 11:57