How to Insert Images in LaTeX

Everything you need to know about including graphics in your LaTeX documents.

The graphicx Package

Image support in LaTeX is provided by the graphicx package. Add it to your preamble to unlock the \includegraphics command:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
% Your content with images goes here
\end{document}

You can also specify a default directory for images using \graphicspath{{images/}} in the preamble, so you do not need to type the full path every time.

Basic Image Insertion

The simplest way to include an image is with \includegraphics followed by the filename. LaTeX will insert the image at its original size:

\includegraphics{diagram.png}

If your image is in a subdirectory, provide the relative path:

\includegraphics{figures/diagram.png}

Sizing Images

You will almost always want to control the size of your images. The most common options are width, height, and scale:

% Set width relative to text width (most common):
\includegraphics[width=\textwidth]{photo.jpg}

% Set width to half the text width:
\includegraphics[width=0.5\textwidth]{photo.jpg}

% Set an absolute width:
\includegraphics[width=8cm]{photo.jpg}

% Scale to 50% of original size:
\includegraphics[scale=0.5]{photo.jpg}

% Set both width and height (may distort):
\includegraphics[width=6cm, height=4cm]{photo.jpg}

% Constrain to fit within a box without distortion:
\includegraphics[width=6cm, height=4cm, keepaspectratio]{photo.jpg}

Using \textwidth or \linewidth is preferred because the image will scale correctly regardless of paper size or margins.

Upload images and compile your document with figures in our online editor.

Try it in our editor

The figure Environment

Wrapping an image in the figure environment makes it a float, allowing LaTeX to position it optimally. This also lets you add a caption and a label for cross-referencing:

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.8\textwidth]{results-chart.png}
    \caption{Performance comparison across all tested models.}
    \label{fig:results}
\end{figure}

You can then refer to the figure elsewhere in your document with Figure~\ref{fig:results}, and LaTeX will insert the correct figure number automatically.

Positioning

The placement specifier in square brackets tells LaTeX your positioning preference. LaTeX treats these as suggestions and may override them for better page layout:

% Force the figure to appear exactly at this point:
\usepackage{float}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.6\textwidth]{architecture.pdf}
    \caption{System architecture overview.}
    \label{fig:architecture}
\end{figure}

You can combine specifiers. For example, [htbp] tells LaTeX to try "here" first, then "top," then "bottom," then a float page.

Multiple Images Side by Side

To place two images next to each other, use minipage environments inside a figure. Each minipage gets its own \includegraphics, caption, and label:

\begin{figure}[htbp]
    \centering
    \begin{minipage}{0.48\textwidth}
        \centering
        \includegraphics[width=\textwidth]{before.png}
        \caption{Before processing.}
        \label{fig:before}
    \end{minipage}
    \hfill
    \begin{minipage}{0.48\textwidth}
        \centering
        \includegraphics[width=\textwidth]{after.png}
        \caption{After processing.}
        \label{fig:after}
    \end{minipage}
\end{figure}

The \hfill command inserts flexible horizontal space between the two minipages. Setting each minipage to 0.48\textwidth leaves a small gap in the middle.

Test side-by-side figures and other layouts instantly.

Try it in our editor

Supported Formats

LaTeX supports different image formats depending on the compiler:

For best results with pdflatex, use PNG for screenshots and diagrams with sharp lines, JPG for photographs, and PDF for vector graphics (charts, diagrams exported from tools like Inkscape or Matplotlib).