0

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?

  • 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 05 '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 05 '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 05 '11 at 21:29
  • Follow the suggestion of https://tex.stackexchange.com/questions/165021/fixing-the-location-of-the-appearance-in-algorithmicx-environment. Solved the issue for me ! – Alan CN Jun 07 '17 at 02:46

1 Answers1

-1

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]
recluze
  • 4,201
  • [!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 06 '11 at 11:57