A blog by Rob J Hyndman 

Twitter Gplus RSS

Controlling figure and table placement in LaTeX

Published on 11 November 2009

It can be frus­trat­ing try­ing to get your fig­ures and tables to appear where you want them in a LaTeX doc­u­ment. Some­times, they just seem to float off onto another page of their own accord. Here is a col­lec­tion of tools and ideas that help you get con­trol of those pesky floats.

Use the place­ment options: h, t, b and p. For example

\begin{figure}[htb]

causes LaTeX to try to fit the float “here”, or at the “top” of the cur­rent page (or the next page), or at the “bot­tom” of the cur­rent page (or the next page). If “p” is spec­i­fied, it will allow the float to take a whole page to itself. You can’t spec­ify only “h” as that is too restric­tive, and LaTeX will auto­mat­i­cally change it to “ht”. The default set­ting is “tbp”.

One of the rea­sons that the floats won’t go where you want them is that there are a lot of con­straints on where they can go. The main ones are

Counter Default
topnumber max­i­mum num­ber of floats at top of page 2
bottomnumber max­i­mum num­ber of floats at bot­tom of page 1
totalnumber max­i­mum num­ber of floats on a page 3
Com­mand
\topfraction max­i­mum frac­tion of page for floats at top 0.7
\bottomfraction max­i­mum frac­tion of page for floats at bottom 0.3
\textfraction min­i­mum frac­tion of page for text 0.2
\floatpagefraction min­i­mum frac­tion of float­page that should have floats 0.5

These can all be changed indi­vid­u­ally. But it is often eas­ier to add ! before the place­ment options, thus forc­ing LaTeX to ignore most of these con­traints. For exam­ple, I often use

\begin{figure}[!htb]

If you want to change the defaults, the fol­low­ing val­ues give rea­son­able results:

\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.85}
\renewcommand{\textfraction}{0.15}
\renewcommand{\floatpagefraction}{0.7}

The \clearpage com­mand starts a new page and inserts all floats that have not yet appeared before con­tin­u­ing. This can leave a bad page break, so a use­ful alter­na­tive is to use the afterpage pack­age, and then insert

\afterpage{\clearpage}

which will put all the floats at the end of the cur­rent page.

A very use­ful pack­age is placeins. This pro­vides the com­mand \FloatBarrier which causes all unprocessed floats to be processed at that point, but does not start a new page unless it is nec­es­sary. To keep floats in the sec­tions in which they were included, use

\usepackage[section]{placeins}

This silently puts a \FloatBarrier com­mand before each sec­tion. There are other options explained in the placeins documentation.

Another use­ful pack­age is flafter. This causes floats to always appear after their place­ment in the document.

If you really don’t want LaTeX to move your float at all, then use the float pack­age with the com­mand \restylefloat{figure} in the pre­am­ble. This allows you to spec­ify [H] as the posi­tion para­me­ter which means “Here and only Here”. How­ever, this often gives bad page breaks.


Related Posts:


 
Tags:
19 Comments  comments 
  • http://www.ingenieure-ohne-grenzen.org Jake

    Thanks a lot for this help­ful overview, Rob!

  • Xin

    I have a prob­lem. For two col­umn arti­cle, is there a sim­ple way to put a cross-​​column fig­ure at the top of cur­rent page? it seems to me that latex will always put it in the next page.

    • http://robjhyndman.com Rob J Hyndman

      Accord­ing to the mul­ti­col pack­age user guide, this is not pos­si­ble. I guess you could move the fig­ure* envi­ron­ment ear­lier in the doc­u­ment so it floats for­ward to where you want it.

      • Sou­vikme­tia

        Hi Rob, I am fac­ing a prob­lem related to the Table adjust­ment. I have table code which make the table(big table) to con­tain in one page, but when i want to give it a def­i­nite posi­tion, instead of placed in the given posi­tion, it goes to cou­ple of page later. How can i solve it?

  • Nan Qu

    I recently found the envi­ron­ment of mini­page is very handy when insert­ing fig­ures and tables.

    Hi Rob, can I ask a ques­tion in R plot­ting?
    Does R facil­i­tate fill­ing the area under a curve?

    Thanks!

    • http://robjhyndman.com Rob J Hyndman

      Use the poly­gon() function.

  • Pingback: Controlling figure and table placement in LaTeX « Idyawati's Blog

  • http://elhilal.blogspot.com najmi

    Some­times I used mini­page since I can’t really con­trol the *exact* posi­tion of the figure/​tables, even using htb

  • Pingback: LaTeX – Force Image Within Section | 3StrandsOfHair

  • Tom3ld

    Awe­some, thanks so much

  • Cuneyt Ertal

    This what I search­ing for a long time. Thank you so much.

  • Chris

    I have 5 fig­ures in a row and text before­hand and after­wards. Now I want the text before­hand, then the 5 fig­ures and then the text after­wards. I tried /​floatbarrier — but it puts the last fig­ure on a seper­ate page before start­ing with the next text.
    What am I doing wrong?

  • Henry

    Very use­ful, Thanks a lot!

  • Rob

    Thanks for the use­full and com­pre­hen­sive overview!!

  • Jithin

    Great tips. Thanks a lot.

  • Pingback: Research tips – Controlling figure and table placement in LaTeX « Rearchitecting

  • Joseeek

    wow works great in texshop

  • alek

    dude was that frus­trat­ing… life­saver <3 great work

  • Dimas

    In case any­one had the same prob­lem I had and ended up here, to place multi-​​column floats (like begin{figure*}[b] end{figure*}) in the bot­tom of mul­ti­col­umn text, you need to use the pack­age dblfloatfix.