Take the 2-minute tour ×
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.

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}

\pagestyle{headings}

\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?

share|improve this question
1  
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
1  
@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
    
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Nov 5 '11 at 21:29
add comment

migrated from stackoverflow.com Nov 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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

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]
share|improve this answer
    
[!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
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.