1

Latex changes the order of floats in my document. It moves figure 2 before figure 1. Figure 1 occupies a whole page, therefore I set it to be inserted on a float page, in afterpage environment. How to make sure that all floats appear in the order they are defined in the document? Here's an example:

\documentclass{article}
\pagestyle{plain}
\usepackage{calc}
\usepackage{setspace}
\onehalfspacing
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{caption}
\usepackage{floatrow}
\usepackage{afterpage}
\setlength{\textfloatsep}{20pt}
\setlength{\intextsep}{20pt}

\begin{document}
\vspace*{0.9\textheight}

\blindtext[8] (See Figure \ref{Fig1}) \blindtext[8] 

\afterpage{
\begin{figure}[p]
\ffigbox[\FBwidth]{%
\framebox{\begin{minipage}[t][0.8\textheight]{0.8\textwidth}%
\hspace*{\fill}%
\end{minipage}}}{\caption{\label{Fig1}This is figure 1. \blindtext[8]}}
\end{figure}
\clearpage }

\blindtext[34] (See Figure \ref{Fig2}). \blindtext[12]

\begin{figure}
\ffigbox[\FBwidth]{%
\framebox{\begin{minipage}[t][3cm]{0.8\textwidth}%
\hfill{}%
\end{minipage}}}{\caption{\label{Fig2}This is figure 2. \blindtext[4]}}
\end{figure}

\blindtext[10] (See Figure \ref{Fig3}) \blindtext[5] 

\begin{figure}
\noindent \centering{}\ffigbox[\FBwidth]{%
\framebox{\begin{minipage}[t][0.3\textheight]{0.8\textwidth}%
\hspace*{\fill}%
\end{minipage}}}{\caption{\label{Fig3}This is figure 3. \blindtext[4] }}
\end{figure}

\end{document}

And the pdf result:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

  • 1
    Latex never re-orders floats (except for a bug in 2-column floats fixed in fixltx2e package) by putting it in afterpage you have manually re-ordered it so in that case you are responsible for ensuring the correct order. Why use \afterpage here? – David Carlisle Mar 14 '15 at 18:57
  • If you remove the afterpage "wrapper", the intended ordering prevails. – Mico Mar 14 '15 at 18:59
  • @DavidCarlisle This is a simplified example only for demonstration purpose. The original document is a multisection document with a lot of figures. If I remove \afterpage in the original document, the big one-page figure and all the following figures are pushed to the end of the section onto float pages, which is not acceptable. How can I prevent that if I remove \afterpage? – bcsikos Mar 14 '15 at 19:25
  • There are lots of answers on site for controlling float placement. hard to give any advice with so little information. The \afterpage usage here theough is simply wrong and will re-order the floats as you found. At the very least you should use \afterpage{\clearpage But I'd never use a float in an afterpage like this (and I wrote that package) – David Carlisle Mar 14 '15 at 19:56
  • @DavidCarlisle Thank you. I see I can't use \afterpage like this (by the way I found that solution at tex.stackexchange.com/questions/52515/…). I asked another question with another MWE where I don't use \afterpage: tex.stackexchange.com/questions/233304/…. – bcsikos Mar 16 '15 at 0:22
2

The only thing \afterpage is doing here is taking the floats out of the default ordering, just remove it.

\documentclass{article}
\pagestyle{plain}
\usepackage{calc}
\usepackage{setspace}
\onehalfspacing
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{caption}
\usepackage{floatrow}
\usepackage{afterpage}
\setlength{\textfloatsep}{20pt}
\setlength{\intextsep}{20pt}

\begin{document}
\vspace*{0.9\textheight}

\blindtext[8] (See Figure \ref{Fig1}) \blindtext[8] 


\begin{figure}[p]
\ffigbox[\FBwidth]{%
\framebox{\begin{minipage}[t][0.8\textheight]{0.8\textwidth}%
\hspace*{\fill}%
\end{minipage}}}{\caption{\label{Fig1}This is figure 1. \blindtext[8]}}
\end{figure}


\blindtext[34] (See Figure \ref{Fig2}). \blindtext[12]

\begin{figure}
\ffigbox[\FBwidth]{%
\framebox{\begin{minipage}[t][3cm]{0.8\textwidth}%
\hfill{}%
\end{minipage}}}{\caption{\label{Fig2}This is figure 2. \blindtext[4]}}
\end{figure}

\blindtext[10] (See Figure \ref{Fig3}) \blindtext[5] 

\begin{figure}
\noindent \centering{}\ffigbox[\FBwidth]{%
\framebox{\begin{minipage}[t][0.3\textheight]{0.8\textwidth}%
\hspace*{\fill}%
\end{minipage}}}{\caption{\label{Fig3}This is figure 3. \blindtext[4] }}
\end{figure}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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