17 Floats
As discussed before, whenever the text you are setting in the .tex file runs beyond the limit of the current page, it’s simply continued in the next page, similarly to what would happen in Word or Pages. Such rule cannot be applied to figures and tables, which need to appear entirely on one page – this is the rationale for using float objects in LaTeX. Floats is the name for a special category of objects in LaTeX, namely those that, unlike text, cannot be split between two pages. Those objects are figures and tables. Whenever you enter a floating environment in LaTeX, you follow it by square brackets, in which you specify the default position it should appear on a new page. You will see the example of this in the next section, applied to figure positioning.
The idea of floats results in a minor, yet very important distinction in LaTeX when it comes to starting a new page. As mentioned earlier in this course, both \newpage and \clearpage can be used to create a new page. However, in the situation when there’s some float pending to be printed on the next page, \clearpage will result in a separate page(s) in which all the queued floats will be inserted, and a new separate page for text will be inserted. When \newpage is used, on the other hand, it will simply create a new page, even if there’s a float on it. The difference can be seen when typesetting the two variants below:
Some text \vspace{10cm}
Some other text \vspace{5cm}
\begin{figure}
\centering
\includegraphics[width = 0.8\textwidth]{koala.jpg}
\caption{This is a picture of coala.}
\label{coala}
\end{figure}
\newpage
This is some more text.
Some text \vspace{10cm}
Some other text \vspace{5cm}
\begin{figure}
\centering
\includegraphics[width = 0.8\textwidth]{koala.jpg}
\caption{This is a picture of coala.}
\label{coala}
\end{figure}
\clearpage
This is some more text.
17.1 Float Location
Figure is an example of one of the two float objects in LaTeX. You can use square brackets to choose the figure’s location on the page. Depending on the letter – h, t, b we can select the figure to be placed here, at the top of the page or at its bottom. However, note that LaTeX has some built-in parameters to determine what a ‘good’ positioning of a float object is. You may use the ‘!’ with your placement specification to force LaTeX to override its default parameters and rely on your suggestion instead.
Some sample text.
\begin{figure}[h!]
\includegraphics[width=\textwidth]{koala.jpg}
\end{figure}
Other sample text.