How to Add Images in LaTeX

Updated June 2026

To add an image in LaTeX, load the graphicx package with \usepackage{graphicx} in your preamble, then use \includegraphics[width=\linewidth]{filename} where you want the image. Wrap it in a figure environment to add a caption and label. On LetX you can upload the image file and compile instantly in the browser — no local TeX install needed.

Step by step

  1. 1

    Load graphicx

    Add \usepackage{graphicx} to your preamble (before \begin{document}).

  2. 2

    Upload the image

    Upload your .png, .jpg, or .pdf into the project so LaTeX can find it.

  3. 3

    Insert the image

    Use \includegraphics[width=0.8\linewidth]{filename} where you want it to appear.

  4. 4

    Add a caption

    Wrap it in a figure environment with \caption{...} and \label{fig:...} for cross-referencing.

  5. 5

    Compile

    Compile to PDF. On LetX this takes a few seconds and updates the live preview.

Example

\usepackage{graphicx}
% ...
\begin{figure}[h]
  \centering
  \includegraphics[width=0.8\linewidth]{diagram.png}
  \caption{System architecture.}
  \label{fig:arch}
\end{figure}

Refer to the figure in text with Figure~\ref{fig:arch}. The [h] placement hint asks LaTeX to put the figure “here”; use [ht] or [H] (with thefloat package) for stricter control.

Float placement options

LaTeX treats figures as floats — it moves them to wherever the page breaks best. The bracket option tells LaTeX where you would prefer the figure to go:

OptionMeaningWhen to use
[h]“Here”, if it fitsSmall figures inside running text
[t]Top of a pageDefault look of most journals
[b]Bottom of a pageRarely needed alone
[p]A separate floats-only pageFull-page figures
[ht]Here, else topGood general default
[H]Exactly here (needs \usepackage{float})Theses, lab reports — when position must not move

Two images side by side

Use the subcaption package, with one subfigure per image:

\usepackage{graphicx}
\usepackage{subcaption}
% ...
\begin{figure}[ht]
  \centering
  \begin{subfigure}{0.48\linewidth}
    \includegraphics[width=\linewidth]{before.png}
    \caption{Before}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.48\linewidth}
    \includegraphics[width=\linewidth]{after.png}
    \caption{After}
  \end{subfigure}
  \caption{Comparison of results.}
  \label{fig:compare}
\end{figure}

Wrap text around an image

\usepackage{wrapfig}
% ...
\begin{wrapfigure}{r}{0.4\linewidth}  % r = right side
  \centering
  \includegraphics[width=\linewidth]{portrait.jpg}
  \caption{A wrapped figure.}
\end{wrapfigure}

{r} floats the image on the right with text flowing around it; use {l} for the left. Avoid wrapfig near page breaks, lists, or section headings — it does not break across pages.

Rotate, crop, and scale

\includegraphics[angle=90]{wide-chart.pdf}          % rotate 90°
\includegraphics[scale=0.5]{photo.jpg}              % half size
\includegraphics[trim=10 20 10 20, clip]{plot.pdf}  % crop l b r t (pt)
\includegraphics[height=5cm, keepaspectratio]{logo.png}

Images in a folder

Keep figures organized in a subfolder and point graphicx at it once in the preamble:

\graphicspath{{figures/}{plots/}}
% then simply:
\includegraphics[width=\linewidth]{result1}  % finds figures/result1.png

Omitting the file extension lets the engine pick the best available format automatically.

Common image errors

ErrorCauseFix
File `x.png' not foundWrong name/path; case-sensitiveMatch the exact filename; check it is uploaded
Undefined control sequence \includegraphicsgraphicx not loadedAdd \usepackage{graphicx} to the preamble
Unknown graphics extension .epspdfLaTeX cannot read EPS directlyConvert to PDF, or add \usepackage{epstopdf}
Figure appears on the wrong pageFloat placementUse [ht], or [H] with the float package

Frequently asked questions

Which image formats does LaTeX support?

pdfLaTeX supports PNG, JPG, and PDF. EPS works with the classic latex+dvips route or by converting to PDF. On LetX, PNG/JPG/PDF work out of the box.

How do I resize an image in LaTeX?

Use the width or height option: \includegraphics[width=0.5\linewidth]{file} scales to half the text width. You can also use scale=0.5 to scale by a factor.

Why does my image not show up?

Check that the file is uploaded to the project, the filename matches exactly (case-sensitive), and graphicx is loaded. On LetX, the file browser shows what is available to include.

How do I center an image in LaTeX?

Put \centering inside the figure environment, right before \includegraphics. Outside a figure, wrap the image in \begin{center}...\end{center}.

How do I put two images side by side?

Load the subcaption package and place two subfigure blocks of width 0.48\linewidth inside one figure, separated by \hfill. Each subfigure gets its own caption.

How do I force a figure to stay where I put it?

Load \usepackage{float} and use \begin{figure}[H]. The capital H pins the figure exactly at that point instead of letting it float.

How do I wrap text around a figure?

Use the wrapfig package: \begin{wrapfigure}{r}{0.4\linewidth} floats the image right with text flowing around it. Avoid it near page breaks and headings.

Try this in LetX now

Open the editor, paste the example, and compile in seconds — free, in your browser.

Start Writing Free