How can I convince LaTeX to keep floating environments such as table and figure close to where I write them in the document source code?

This question is marked "community wiki".

asked 30 Jan, 23:50

stefan's gravatar image

stefan ♦♦
862
accept rate: 42%

wikified 01 Feb, 10:25


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{figure}[!htbp]

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)

Example:

text
\begin{minipage}{\linewidth}
\begin{center}
\includegraphics[width=.6\linewidth]{example-image}
\captionof{figure}{An example image not including a Wombat}
\end{center}
\end{minipage}
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.

I originally wrote this text on TeX.SE and share it here.

permanent link

answered 30 Jan, 23:51

stefan's gravatar image

stefan ♦♦
862
accept rate: 42%

edited 01 Feb, 10:19

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×1
×1
×1
×1

question asked: 30 Jan, 23:50

question was seen: 436 times

last updated: 01 Feb, 10:25

Related questions