LaTeX
  • How I learn LaTeX?
  • Installation and Customization
    • Online
    • Offline
  • LaTeX Basics
  • Text Manipulation
    • Fonts, Size and Styles
  • Math Manipulation
  • Advanced Math Manipulation
  • Lists
  • Tables
  • Pictures, Figures
  • Unit in LaTeX
  • Document Structure
  • Document Formatting
    • Headers and Footers, Page Numbering
    • Spacing in Paragraphs
    • Page size, Margins
    • Coloring
    • Footnotes
  • Multi-file LaTeX project
Powered by GitBook
On this page
  • Importing an image
  • Customize your pictures
  • Positioning your images
  • Wrapping text around figures
  • Captioning
  • Labelling and cross-referencing

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\LaTeXLATE​X that images are kept in a folder named images.

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

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.

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\LaTeXLATE​X will position it in a such way that it fits the flow of the document.

Here is an example:

\usepackage{float}

\begin{figure}[H]
\includegraphics[width=8cm]{Plot.png}
\centering
\end{figure}

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.

\begin{wrapfigure}[lineheight]{position}{width}
  ...
\end{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:

\documentclass{article}
\usepackage{float}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}

\begin{wrapfigure}{L}{0.35\textwidth}
\centering
\includegraphics[scale=0.1]{./stars.png}
\end{wrapfigure}

There are several ways to plot a function of two variables, 
depending on the information you are interested in. For 
instance, if you want to see the mesh of a function so it 
easier to see the derivative you can use a plot like the 
one on the left.

\begin{wrapfigure}{R}{0.35\textwidth}
\centering
\includegraphics[scale=0.1]{./stars.png}
\end{wrapfigure}

On the other side, if you are only interested on
certain values you can use the contour plot, you 
can use the contour plot, you can use the contour 
plot, you can use the contour plot, you can use 
the contour plot, you can use the contour plot, 
you can use the contour plot, like the one on the left.

On the other side, if you are only interested on 
certain values you can use the contour plot, you 
can use the contour plot, you can use the contour 
plot, you can use the contour plot, you can use the 
contour plot, you can use the contour plot, 
you can use the contour plot, 
like the one on the left.
\end{document}

And we have:

Captioning

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

\begin{figure}[H]
\centering
\includegraphics[scale=0.25]{./stars.png}
\caption{The Milky Way}
\end{figure}

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:

\begin{figure}[h]
    \centering
    \includegraphics[width=0.25\textwidth]{mesh}
    \caption{a nice plot}
    \label{fig:mesh1}
\end{figure}

As you can see in the figure \ref{fig:mesh1}, the 
function grows near 0. Also, in the page \pageref{fig:mesh1} 
is the same example.

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.

  • \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.

PreviousTablesNextUnit in LaTeX

Last updated 1 year ago

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

\label must be placed after \caption.

Why?
table environment