Automating image positioning

When there's not enough free space on a page when you include an image, that image will go to the next page. This will leave white space at the end of the page. You could manually move some text to compensate. But imagine having a large document with many images; manually moving images to balance page breaks could cause a headache. Fortunately, LaTeX provides an automatism for us.

How to do it...

This is a very common way of including images as figures:

  1. Use a figure environment.
  2. Center the content, if desired.
  3. Include the image.
  4. Add a caption.
  5. Add a label for cross-referencing.

A typical command sequence is as follows:

\begin{figure}[htbp!] \centering \includegraphics{filename} \caption{Some text} \label{fig:name} \end{figure} ...

Get LaTeX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.