Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up

Inserting images in LaTeX

This guide explains how to insert images in your LaTeX documents: supported formats, resizing, float positioning, captions and cross-references.

Prerequisites

To use images, you need to load the graphicx package in the preamble:

LaTeX
\documentclass{article}
\usepackage{graphicx}  % Package for images
\begin{document}
% Your content
\end{document}
Supported formats With pdfLaTeX: .png, .jpg, .jpeg, .pdf. With XeLaTeX/LuaLaTeX: all these formats plus .eps.

Basic insertion

The basic command is \includegraphics{filename}:

LaTeX
% Image in the same folder as the .tex file
\includegraphics{mon-image.png}

% Image in a subfolder
\includegraphics{images/photo.jpg}

% Extension is optional (LaTeX guesses it)
\includegraphics{mon-image}
On Sarmate.net Upload your images via the file manager. They will be available in the same folder as your .tex file or in a subfolder of your choice.

Controlling dimensions

Several options allow you to resize the image:

LaTeX
% Fixed width
\includegraphics[width=8cm]{image.png}

% Fixed height
\includegraphics[height=5cm]{image.png}

% Width relative to text width
\includegraphics[width=0.8\textwidth]{image.png}

% Scale (1 = original size)
\includegraphics[scale=0.5]{image.png}

% Width AND height (may distort)
\includegraphics[width=6cm, height=4cm]{image.png}

% Preserve proportions with keepaspectratio
\includegraphics[width=6cm, height=4cm, keepaspectratio]{image.png}
Option Description Example
width Image width width=10cm
height Image height height=5cm
scale Scale factor scale=0.75
angle Rotation in degrees angle=90
keepaspectratio Preserves aspect ratio keepaspectratio

The figure environment

To add a caption and automatic numbering, use the figure environment:

LaTeX
\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.7\textwidth]{graphique.png}
    \caption{Évolution des ventes en 2024}
    \label{fig:ventes}
\end{figure}

% Référence dans le texte
Comme le montre la figure~\ref{fig:ventes}, les ventes ont augmenté.

Positioning options

The letters in brackets [htbp] tell LaTeX where to place the figure:

Option Position
h Here - where it is declared (if possible)
t Top - at the top of a page
b Bottom - at the bottom of a page
p Page - on a dedicated float page
! Forces LaTeX to be less strict
H Exactly here (requires the float package)
Floating figures LaTeX may move figures to optimize the layout. This is normal behavior. Use references (\ref) rather than "the image below".

Centering an image

Several methods exist:

LaTeX
% Method 1: \centering (inside figure)
\begin{figure}[h]
    \centering
    \includegraphics[width=0.5\textwidth]{image.png}
    \caption{My caption}
\end{figure}

% Method 2: center environment (outside figure)
\begin{center}
    \includegraphics[width=0.5\textwidth]{image.png}
\end{center}

Subfigures (side by side images)

The subcaption package allows you to place multiple images within the same figure:

LaTeX
\usepackage{subcaption}  % In the preamble
\begin{figure}[htbp]
    \centering

    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{image1.png}
        \caption{Première image}
        \label{fig:image1}
    \end{subfigure}
    \hfill  % Horizontal space between images
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{image2.png}
        \caption{Deuxième image}
        \label{fig:image2}
    \end{subfigure}

    \caption{Comparaison des deux images}
    \label{fig:comparaison}
\end{figure}
Tip The sum of subfigure widths must be less than \textwidth. With 0.45\textwidth each, 10% remains for spacing (\hfill).

Text wrapping around an image

The wrapfig package allows text to flow around an image:

LaTeX
\usepackage{wrapfig}  % In the preamble
\begin{wrapfigure}{r}{0.4\textwidth}  % r = right, l = left
    \centering
    \includegraphics[width=0.38\textwidth]{photo.png}
    \caption{A photo}
\end{wrapfigure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. The text continues and wraps around the image...

List of figures

Automatically generate a list of all figures:

LaTeX
\listoffigures  % Generates "List of Figures"

Complete example

LaTeX
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{subcaption}

\title{Report with images}
\author{Your name}

\begin{document}

\maketitle

\section{Introduction}

Here is a simple centered image:
\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.6\textwidth]{logo.png}
    \caption{Company logo}
    \label{fig:logo}
\end{figure}

As can be seen in figure~\ref{fig:logo}, the logo is composed of several elements.
\section{Comparison}

\begin{figure}[htbp]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{avant.png}
        \caption{Before}
        \label{fig:avant}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{apres.png}
        \caption{After}
        \label{fig:apres}
    \end{subfigure}
    \caption{Before/after comparison}
    \label{fig:comparaison}
\end{figure}

Figure~\ref{fig:comparaison} shows the evolution between the initial state (\ref{fig:avant}) and the final state (\ref{fig:apres}).
\end{document}

Draw your own vector figures with TikZ

Rather than importing images, create your diagrams, schemas and mathematical functions directly in LaTeX. Our free 15-lesson tutorial shows you how.

Open TikZ tutorial

Ready to illustrate your documents?

Upload your images and create professional documents

Create a free account