LaTeX floats
Before we start with tables and images, the topic of floats should be touched upon. While you can place your tables, images, and other objects as is, floats could help to arrange their positioning on the page regardless of where you declare them, as well as provide some additional features.
Contents
Floats ↩
By default, you have figure
and table
float environments, and you can declare your own additional float styles with the float
1 package. Since all float environments behave similarly, I will show their features using the figure
environment:
\lipsum[1]
\begin{figure}
\includegraphics[width=0.5\linewidth]{pugknight}
\end{figure}
\lipsum[2-5]
As you see, while the figure is declared after \lipsum[1]
text block, it is placed at the top of the page. You can control this behaviour by using the placement specifier:
\begin{figure}[b]
The possible values of this parameter are:
Specifier | Placement |
---|---|
t | Top of the page (default) |
b | Bottom of the page |
h | "Here", approximately at the point of declaration |
H | Precisely at the point of declaration (declared in the float package) |
p | Separate floats-only page |
! | When added to the specifier, "forces" it, overriding internal parameters |
The placeins
2 package grants you some additional control over where floats appear in the document, by introducing the \FloatBarrier
command, preventing floats being placed after the barrier. More conveniently, you can call this package with the section
option (\usepackage[section]{placeins}
) to forbid float placement after the start of a new \section
. Other possible options are [above]
, to allow the floats to appear above their own section (on the same page), and [below]
, to allow the floats to appear below the start of the next section (on the same page).
Style ↩
The usual \centering
command will center the float if its width is smaller that your text's width.
With the float
package, you can use the \floatstyle
and \restylefloat
commands to change the appearance of a certain class of floats.
\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}
The possible style parameters include:
plain
- the default style, caption below the contentplaintop
- same, caption above the contentboxed
- surrounded by a box, caption below the boxruled
- surrounded by horizontal rules, caption above the content
Captions ↩
Captions are pretty straightforward: \caption{Text}
placed inside the float environment will do the job. If you haven't defined a float style previously, you can control the caption placement just by placing its command before or after the content. Another purpose of captions, is to create a \listoffigures
or \listoftables
. You can modify caption formatting and behaviour with a help of the caption
3 package.
📝 NOTE: The floatrow
4 package extends the float
package, providing additional options for the floats, including float width control, caption placement beside the content, putting multiple floats side by side in a row, putting footnotes inside the float, etc.
Discuss this post on Reddit