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

  • 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
  • 1
    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.
    – Teepeemm
    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 ...
    – MS-SPO
    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:


Useful package regarding float placement:

  • float introduces a placement option H enforcing the placement exactly at that point.
  • placeins provides the command \FloatBarrier to limit the floating of figures or tables. You could place such a barrier before and after a listing.
  • afterpage allows a more clever \clearpage, putting the effect off until the page is full: \afterpage{\clearpage}

Completely avoiding a floating environment:

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


\captionof{figure}{An example image not including a Wombat}
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:

  • 2
    Too bad you can't just disable floats from being inserted in a certain portion of the paper...
    – SamB
    Commented Dec 10, 2010 at 21:15
  • 28
    @SamB: You could use \FloatBarrier before and after that portion of the paper or \clearpage (or variants) before and after.
    – Stefan Kottwitz
    Commented Dec 10, 2010 at 21:19
  • 2
    +1: what do you think about mentioning the flafter package?
    – cmhughes
    Commented Feb 28, 2012 at 2:12
  • 1
    @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.
    – Jake
    Commented Apr 5, 2012 at 20:26
  • 3
    H option in float package is very useful to me!
    – updogliu
    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:

  • underspecified position parameters. I recommend always using [htbp] until the document is complete.

  • graphics too large. Do you really need a graph 2/3 the page size?

  • too many graphics near each other. Once graphics start building up, it just isn't possible to keep the last one near its source location.

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.

  • 70
    +1 for "don't worry until you're nearly done".
    – Reid
    Commented Aug 8, 2011 at 17:45
  • 8
    and another +1 for [htbp]. Makes hell of a difference from [ht].
    – mreq
    Commented Mar 24, 2013 at 21:31
  • 1
    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?
    – Max Ghenis
    Commented Jun 1, 2020 at 15:09
  • @MaxGhenis — texfaq.org 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{figure}{H}.

% Example taken from https://tex.stackexchange.com/questions/297564
\usepackage{float} % here for H placement parameter


Text before the table.    

\begin{table}[H] % placement parameter H
    \centering % if you want to center the table
    \caption{Table showing \ldots}
    % Code for table

Text after the table.      

  • 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{figure}[!htb], in nearly all cases it helps. If not then use:


it prevents placing floats before the section.


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].


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{figure}[...]{...} for the captions.

  • Can you elaborate on why a regular caption would not do?
    – einpoklum
    Commented Mar 17, 2016 at 20:34
  • 1
    @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.

  • 6
    \clearpage is useful in combination with the afterpage package to avoid empty space at the end of a page.
    – Stefan Kottwitz
    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.
    – vanden
    Commented Aug 25, 2010 at 2:51

An easy way to specify for LaTeX to place something is by adding an optional argument for position:


where the [h] means here, or


where the [h!] is for forced here. Do these work?

  • 2
    h means that you allow 'here', but by not specifying t, b or p you don't allow placement at 'top', 'bottom' or a float 'page'. Restricting to h makes placement more difficult.
    – Stefan Kottwitz
    Commented Aug 24, 2010 at 23:25
  • 6
    Also LaTeX ignores you and changes it to [ht].
    – TH.
    Commented Aug 25, 2010 at 1:26
  • @TH. - so does LaTeX always ignore h? that's what i deduced after reading this: robjhyndman.com/researchtips/latex-floats. and would you say adding ! is typically a bad idea? one might argue that LaTeX constraints were designed with optimum readability in mind. Commented Aug 25, 2010 at 15:32
  • No, it doesn't always ignore h. What I meant was if you use \begin{figure}[h], LaTeX will spit out a warning that says it's changed the h to ht. I don't have an opinion on whether adding ! is a bad idea or not.
    – TH.
    Commented Aug 25, 2010 at 20:29
  • 2
    Adding ! will direct LaTeX to ignore some of its rules with respect to number of floats on the page or size restrictions, so it increases the chances that a float fitts into "h" or "t", see tex.stackexchange.com/questions/39017/… for a detailed discussion of all the rules Commented Aug 6, 2013 at 19:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .