Graphics, Figures & TablesOrder of appearance of tables and figures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
SpacedOut
Posts: 3
Joined: Sun Oct 02, 2011 4:23 am

Order of appearance of tables and figures

Post by SpacedOut »

I am trying to insert a figure followed by a table. Here is my attempt at a MWE.

Code: Select all

\documentclass{elsarticle}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{epstopdf}

 \begin{figure}[h]
  \caption{blah}
  \includegraphics[scale=.7]{../Documents/cubing.eps} 
 \end{figure}
      
  \begin{center}
    \begin{tabular}{ | l | l | l | l | l | l | l |}
    \hline
    #6 row table
    \end{tabular}
  \end{center}
What happens is the table appears first (it is at the bottom of the page by coincidence), then the figure is on the next page. Any ideas how to fix the order? Thanks in advance for any help.
Last edited by SpacedOut on Sun Nov 27, 2011 5:57 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Order of appearance of tables and figures

Post by Stefan Kottwitz »

Figures are floating objects, they are positioned by LaTeX to give a good layout. You can specify options for their placement in square brackets, like you did with [h]:
  • `h` means here: Place the figure in the text where the figure environment is written, if there is enough room left on the page
  • `t` means top: Place it at the top of a page.
  • `b` means bottom: Place it at the bottom of a page.
  • `p` means page: Place it on a page containing only floats, such as figures and tables.
  • `!` allows to ignore certain restrictions of LaTeX for float placement. This means, if you add `!`, the float will be placed if it fits onto the current page and if there aren't further waiting float objects of the same type, ignoring LaTeX's predefined proportions of text and floats.
These options can be combined, such as `[!htbp]`. Their order doesn't matter, LaTeX itself attempts using allowed places in order `h`, `t`, `b`, `p`, even if `[pbth]` was used.

You should even consider combining as many options as sensible. If a figure cannot be placed, it blocks subsequent figures. This can be a reason why figures end up very late, as you noticed. Specifically, ensure that the figures are not too big to fit into the margins.

This advice is a part of what I wrote here: How to use the placement options [t], [h] with figures?

You could also force the figure to be printed before the table, if you insert \clearpage before the table. Or use a float barrier, this requires loading the placeins package:

Code: Select all

\usepackage{placeins}
and in the text, between the figure and the table you insert the \FloatBarrier command:

Code: Select all

\begin{figure}[ht]
% your figure
\end{figure}
...
\FloatBarrier
...
  \begin{center}
    \begin{tabular}...
Stefan
LaTeX.org admin
SpacedOut
Posts: 3
Joined: Sun Oct 02, 2011 4:23 am

Re: Table and Figure appear in wrong order

Post by SpacedOut »

Great answer! Thank you!
Post Reply