How to Control the Positioning of Floating Figures
In LaTeX, it is possible to create documents with high quality of formatting, with stunning fonts, symbols, and images.
One of the problems people have with LaTeX, however, is that it is difficult to control where elements will be positioned.
The main reason for this is that LaTeX does a lot of work on the behalf of the user. It will automatically determine the best places to break lines, pages, and position elements, such that the general quality of the document is maximized. This is done using advanced algorithms developed by a close comparison with publishing standards.
The downside of this automated process, however, is that it may not be easy to define exactly where an element will appear. Such as the case with floating images. As the name says, they should float on the page, but the location is not specified in standard LaTeX.
Positioning Flags
If you're using the figure environment in LaTeX, there are a few positioning flags that can be used to mitigate this. For example, one can do:
\begin{figure}[h] \includegraphics{figure1.jpg} \end{figure}
this will create a figure environment where the image "figure1.jpg" will be displayed (notice that this may or may not work depending on your particular version of \includegraphics).
The flag used here is "h", and it comes in a square bracket right after the beginning of the figure environment. Here are the available options:
t will display the float on the top of the page
b wil display the float on the bottom of the page
h will display the float on the current position (here)
These flags can also be combined. The order in which they appear will determine also the order in which LaTeX will try to put the figure.
Finally, there is a "!" option that can be added to the previous one. The meaning is that LaTeX will put the figure there, even if it doesn't look good.
Helper Package placeins
Still option is to use the external package placeins (which is available in most modern distributions). This package provides helper functions such as the command "\FloatBarrier". With this command, one can say exactly when LaTeX will make the figure placement, so that it won't wait for later in the process to output the figure.
Here is an example with two figures
\documentclass{article} \usepackage{graphicx} \usepackage{placeins} \begin{document} Text \begin{figure}[h!] \includegraphics{figure1.jpg} \end{figure} \FloatBarrier Text \begin{figure}[h!] \includegraphics{figure2.jpg} \end{figure} \FloatBarrier
This will make sure that LaTeX will put the figures exactly where they are found, even if it results in an ugly page configuration.
Post a comment