Keeping tables/figures close to where they are mentioned

Is there any package or a method to force LaTeX to keep floating environments like table and figure closer to where they are declared?

253k 70 70 gold badges 730 730 silver badges 796 796 bronze badges asked Aug 24, 2010 at 22:19 4,391 4 4 gold badges 20 20 silver badges 8 8 bronze badges

You may also try to relax the rules for placement of floating environments, allowing the page to look worse; among others LaTeX requires that there is enough text on the page if the page is not taken entirely by floats.

Commented Oct 30, 2018 at 19:25

This doesn't answer the question, but: TeX is assuming that you want the environment to float around. This means that you can't write "This table:", because "This table" may move somewhere else. Instead, you should write "as in Table ##". But if you absolutely need the table/figure to appear where you want it, then the answers on this page are for you.

Commented Jun 19, 2019 at 18:42

Have a look here and follow some of the links mentioned: tex.stackexchange.com/questions/2275/… . // BTW, providing code is always a good idea, as you know .

Commented Mar 31 at 8:04

8 Answers 8

Easing the float placement by options:

You could use more positioning options. Not just [h] . If you wish to place the figure near, allow more positioning options, for instance by [htbp] (here, top, bottom, page). Use a ! symbol to remove further restrictions. So, in many cases this is sufficient:

\begin[!htbp] 

Useful package regarding float placement:

Completely avoiding a floating environment:

Package caption allows to add a caption outside a floating environment, meaning at any place you want. Use \captionof (for figures)

text \begin <\linewidth>\begin \includegraphics[width=.6\linewidth] \captionof \end \end even more text 

The minipage keeps graphic and caption together, the center environment add a bit of white space around the figure.

Further reading:

Because it's an important and not easy subject, there's a lot of material to be found, for instance in FAQ collections. There's an extensive document dealing with graphics inclusion, manipulation and placement:

The interesting part for your question may be Part IV: The Figure Environment beginning on page 55.

There is also Frank Mittelbach's excellent answer describing the floating mechanism and related options in great detail:

answered Aug 24, 2010 at 23:21 Stefan Kottwitz ♦ Stefan Kottwitz 234k 84 84 gold badges 676 676 silver badges 829 829 bronze badges Too bad you can't just disable floats from being inserted in a certain portion of the paper. Commented Dec 10, 2010 at 21:15

@SamB: You could use \FloatBarrier before and after that portion of the paper or \clearpage (or variants) before and after.

Commented Dec 10, 2010 at 21:19 +1: what do you think about mentioning the flafter package? Commented Feb 28, 2012 at 2:12

@StefanKottwitz: I've added a link to Frank Mittelbach's float explanation, I hope you don't mind. If you do, please feel free to roll back.

Commented Apr 5, 2012 at 20:26 H option in float package is very useful to me! Commented Dec 7, 2012 at 1:06

Controlling floats isn't difficult once you understand what LaTeX is trying to do with them. Requisite FAQ link: https://texfaq.org/FAQ-floats

Three things, broadly speaking, will prevent floats from staying close to their definition:

Above all, forget about formatting your floats until the document is absolutely finished. You'll produce better results and write the document faster that way.

777k 70 70 gold badges 1.6k 1.6k silver badges 2.5k 2.5k bronze badges answered Aug 24, 2010 at 23:44 Will Robertson Will Robertson 74.8k 18 18 gold badges 183 183 silver badges 213 213 bronze badges +1 for "don't worry until you're nearly done". Commented Aug 8, 2011 at 17:45 and another +1 for [htbp] . Makes hell of a difference from [ht] . Commented Mar 24, 2013 at 21:31

if anyone thinks the faq answer (will provides a link) doesn't say all that's needed, then please feel free to mail the via link at the bottom of the "faq answer page"; i try to keep up with what's said here, but i'm not omnipotent, apparently.

Commented Oct 27, 2013 at 13:05

The FAQ link is broken, and I couldn't find live FAQs when searching tex.ac.uk. Has this resource moved?

Commented Jun 1, 2020 at 15:09 Commented Jun 2, 2020 at 2:12

Check out the float package. It adds ability to include [H] forced here float placement. You can also select this as automatic default with \floatplacement .

\documentclass % Example taken from https://tex.stackexchange.com/questions/297564 \usepackage % here for H placement parameter \begin Text before the table. \begin[H] % placement parameter H \centering % if you want to center the table \caption \label % Code for table \end Text after the table. \end
22.8k 7 7 gold badges 73 73 silver badges 138 138 bronze badges answered Aug 24, 2010 at 23:21 Geoffrey Jones Geoffrey Jones 14.6k 3 3 gold badges 56 56 silver badges 54 54 bronze badges 2022-11-4 (Happy Thanksgiving): I decided to add an MWE that shows how the float package is used. Commented Nov 24, 2022 at 21:33 This answer was the one to solve my problem Commented Apr 14, 2023 at 20:47

try \begin[!htb] , in nearly all cases it helps. If not then use:

\usepackage[section]

it prevents placing floats before the section.

answered Oct 25, 2011 at 7:10 user2478 user2478

Fairly often all that you need is to declare tables and figures earlier, before the first point of reference (for example, one or two paragraphs before the point of reference, or before the previous subsection heading).

Unfortunately, it tends to be a little bit of trial and error. Some kinds of floats need to be declared earlier than others; for example, floats with placement [b] are sometimes trickier than floats with [t] .

55.2k 32 32 gold badges 167 167 silver badges 234 234 bronze badges answered Aug 24, 2010 at 23:54 Jukka Suomela Jukka Suomela 21.2k 15 15 gold badges 76 76 silver badges 94 94 bronze badges

If it is truly critical that your image / table gets placed where you have typed it in the document, then it isn't a float, and why not remove the float environment entirely ie, insert it directly with \captionof[. ] <. >for the captions.

answered Oct 27, 2013 at 11:48 Nicholas Hamilton Nicholas Hamilton 13.3k 8 8 gold badges 48 48 silver badges 86 86 bronze badges Can you elaborate on why a regular caption would not do? Commented Mar 17, 2016 at 20:34

@einpoklum \caption by default only works inside figure , table (and some other similar environments). \captionof (requires caption or capt-of package) on the other hand lets you add a numbered caption outside these environments.

Commented Apr 19, 2016 at 12:51

As @asia1281 mentioned, the [h] directive helps. I did not know of [h!] before (thanks!), but reading around seems to suggest that it isn't quite forced as there may still be circumstances where LaTeX refuses to put the float right there.

Another thing that may help is one of \clearpage and \cleardoublepage . These force all unprocessed floats to be typeset and then a new page or two (with \cleardoublepage and some classes). If you wait until your document is written and you are worrying only about apperance, you can put one of these commands at the end of the text on the very bottom of a page to force the outstanding floats to appear right thereafter. This is really best saved for final stages and needs to be redone (or at least checked) whenever the text is edited.

1,217 1 1 gold badge 12 12 silver badges 24 24 bronze badges answered Aug 24, 2010 at 23:03 31.5k 23 23 gold badges 68 68 silver badges 88 88 bronze badges

\clearpage is useful in combination with the afterpage package to avoid empty space at the end of a page.

Commented Aug 24, 2010 at 23:27

@Stefan Thanks! I'd not know of afterpage. That certainly makes the use of clearpage in these circumstances much easier.