# A TeX example that fails to keep the sequence of floats

I wish to have a TeX example which includes text, figures and tables, where the sequence of elements in the resulting DVI is NOT as it is in the TeX file.

I am looking for this so to see how well different solutions can fix this.

-
As far as I know this is not possible, because LaTeX keeps the floats in a FIFO queue. It can happen when you use the [H] specifier provided by the float package (which I never recommend). Of course, text is mostly independent of floats, because the very purpose of floats is that LaTeX chooses the "best" place where to put them. –  egreg Oct 12 '11 at 22:03
Hi egreg, I rephrased my question in the hopes of making it clearer. I think it is obviously possible to do (since I get this effect in some of my files, which I try to correct using H), I just do not know how to create a good dummy example :) –  Tal Galili Oct 12 '11 at 22:12
This actually can happen if you mix one column and two column floats in a two column document (because the queues are different). I'd be very curious to see an example where this happens in a one column document (without using pseudofloats with [H]). –  egreg Oct 12 '11 at 22:19
@TalGalili: Further to egreg's comment, read the entry on the UK TeX FAQ about Two-column float numbers out of order. –  Werner Oct 12 '11 at 22:20
@TalGalili We will need a minimal example to offer more than rather general statements –  Joseph Wright Oct 13 '11 at 6:06

Does the following example produce the results you want?

Using the [p] option on the table and figure floats means that they get pushed to their own 'float' page, as such "the sequence of elements in the resulting DVI is NOT as it is in the TeX file."

\documentclass{article}

\usepackage{lipsum}

\begin{document}

\lipsum

\begin{table}[p]
\centering
\begin{tabular}{cc}
1   &   2
\end{tabular}
\caption{Table}
\end{table}

\lipsum

\lipsum[1]

\begin{figure}[p]
\centering
\rule{20pt}{10pt}
\caption{Figure}
\end{figure}

\lipsum[2]
\end{document}

-

The following minimal example produces an out-of-sequence figure placement, based on the comments made here, as well as the UK TeX FAQ entry: Two-column float numbers out of order

\documentclass[twocolumn]{article}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\lipsum[1-3]
\begin{figure*}
\centering\includegraphics{figure1}% This figure is on page 2
\caption{First figure} \label{figure1}
\end{figure*}
Here is a reference to Figure~\ref{figure1}.
\lipsum[4-6]
\begin{figure}
\centering\includegraphics{figure2}% This figure is on page 1
\caption{Second figure} \label{figure2}
\end{figure}
Here is a reference to Figure~\ref{figure2}.
\lipsum[7-9]
\end{document}


lipsum provides dummy text, while the demo package option to graphicx allows for all images (existing or non-existent) to be replaced by a 150pt x 100pt black rectangle.

The reason for this out-of-sequence placement of figures (floats in general), is because TeX keeps separate FIFO lists for one- and two- column floats. Since the first figure is placed in the one-column float list (by using the starred version *) and the second is placed in the two-column float list but can still fit on the page, it is typeset first. The deferred first figure is typeset on page 2, since that's the default behaviour of multi-column spanning floats in two-column mode.

A solution is provided by using the fixltx2e package that uses a single FIFO list for deferred floats.

-