Pictures, Figures

Images are essential elements in most of the scientific documents. In this article we explain how to include images in the most common formats, how to customize, and reference them.

Importing an image

Before adding a picture, make sure to include that picture in the same directory as your .tex file. Below is an example showing how to add a picture into your document:

\usepackage{graphicx}
\graphicspath{{./images/}}
\begin{document}
Here is the picture of a broken QR code:

\includegraphics[scale=0.3]{qr.png}
\end{document}

In this example, we specifically import a package called graphicx, which manages and include the image in the document. I will introduce to you some new commands:

  • \graphicspath{{./images/}} - Tells LaTeX\LaTeX that images are kept in a folder named images.

circle-info

In this context, the dot sign (.) means the root directory - which is the directory the .tex file is being located.

circle-info

You can also, specify an absolute path (fullpath) like this:

\graphicspath{{D:/TeX//figures/}}

or specify multiple paths at once:

\graphicspath{{subdir1/}{subdir2/}{subdir3/}...{subdirn/}}

  • \includegraphics{picture.png} - includes the image in the document. qr.png in this case is the name of the image.

circle-info

If you use \graphicspath, you can omit the extension of the file and let LaTeX search for all the supported formats.

Customize your pictures

There are multiple settings that allow users to customize the picture:

settings
meaning

scale=number

enlarge or minimize the picture

width=5cm

specify the width

height=5cm

specify the height

angle=number

rotate your picture x degrees counter-clockwise. (negative number does the opposite)

Positioning your images

In order to position your picture, you need to wrap it in a container. In this case, we use the figure environment. The figure environment is used to display pictures as floating elements within the document. This means you include the picture inside the figure environment and you don't have to worry about it's placement, LaTeX\LaTeX will position it in a such way that it fits the flow of the document.

The way figure works is the same as table environment. You can check table environment to understand.

Here is an example:

Wrapping text around figures

It's possible to wrap the text around figures. In order to do that, we need to import the wrapfig package. This package brings a new environment called wrapfigure and we can place an \includegraphics command inside it to create a wrapped figure. Here is the syntax of wrapfigure.

Explanation:

  • Position has 4 main values:

    • r/R: right side of the text

    • l/L: left side of the text

    • the uppercase value makes the figure become float. (which means "place exactly here")

  • width: width of the figure container

Let's look at an example:

And we have:

Captioning

It's easy to create a caption in LaTeX\LaTeX:

circle-info

The position of the caption depends on the position of \caption command.

Labelling and cross-referencing

In order to label a figure, as well as make reference to it at somewhere in the document:

Explanation:

  • \label{fig:mesh1} - labeling your figure, note that the name inside you can set anything you want, but since this is a figure of a mesh, I will set it fig:mesh1.

circle-info

\label must be placed after \caption. Why?arrow-up-right

  • \ref{fig:mesh1} - print the number assigned to your figure, it also create a hyperlink leading you to the figure's position.

  • \pageref{fig:mesh1} - print the page number where the figure locates.

Last updated