How to Insert a JPG Image in LaTeX (graphicx, figure, wrapfig)

Updated Tested on TeX Live 2025 (pdfLaTeX), Oct 2026 7 min read

Quick answer

To add a JPG image in LaTeX, load the graphicx package with \usepackage{graphicx} and call \includegraphics[width=0.8\textwidth]{photo.jpg} in the body. Wrap it in a figure environment to add a caption and label. Compile with pdfLaTeX, XeLaTeX or LuaLaTeX; plain latex (DVI output) cannot read JPG files.

A JPG is inserted by graphicx at the size stored in the file, not at a size that fits the page. Most image problems in LaTeX come from that, or from figures floating.

What you’ll learn:

Insert a JPG image with graphicx

Use this for any JPG, PNG or PDF image. graphicx ships with every TeX distribution and Overleaf.

  1. Load the package in the preamble:

    \documentclass{article}
    \usepackage{graphicx}
    \begin{document}
  2. Insert the image in the body with \includegraphics:

    \includegraphics[width=0.8\textwidth]{example.jpg}
  3. Keep the JPG in the same folder as your .tex file, or give a relative path such as images/example.jpg.

Result: the image appears inline at 80% of the text width.

JPG photo inserted into a LaTeX document with includegraphics, shown in the compiled PDF

If all your images live in one subfolder, set the search path once and drop the folder from every call:

\graphicspath{{images/}} % in the preamble; note the double braces

You can also omit the extension (\includegraphics{example}), and graphicx looks for a supported file with that name.

Note: \includegraphics with no options does not shrink the image to fit. It uses the size implied by the file’s resolution metadata, so a large photo can run past the margin. Always set a width.

PDF pages use the same command; to insert a PDF page as a figure, add page=2 to the options.

Which compiler can read JPG?

pdfLaTeX, XeLaTeX and LuaLaTeX all read JPG and PNG directly and embed the file unchanged. Plain latex (DVI output) can’t, and stops with “Cannot determine size of graphic … (no BoundingBox)”.

In Overleaf, make sure the project’s compiler setting is pdfLaTeX, XeLaTeX or LuaLaTeX, not LaTeX.

Set the image size

Use this whenever the image is larger or smaller than you want. Set one dimension and graphicx scales the other to keep the aspect ratio.

\includegraphics[width=\textwidth]{image.jpg} % full text width
\includegraphics[height=5cm]{image.jpg} % 5 cm tall, width follows

JPG image scaled to a height of 5 cm in a LaTeX document

If you set both width and height, the image is stretched to that box. Add keepaspectratio to fit inside the box instead:

\includegraphics[width=0.5\textwidth, height=5cm, keepaspectratio]{image.jpg}
OptionWhat it doesExample
width=\textwidthFull width of the text blockwidth=0.5\textwidth
width=\linewidthWidth of the current line (use inside columns, minipages and lists)width=0.9\linewidth
Absolute unitsFixed size in cm, mm, in or ptwidth=10cm
scale=Multiplies the natural sizescale=0.5
keepaspectratioWith both width and height, fits inside without distortionwidth=5cm, height=5cm, keepaspectratio

For sharp print output, start from an image of at least 300 DPI at its printed size. Scaling down a large image keeps quality; scaling up a small one doesn’t.

JPG image scaled to half the text width inside a figure

Rotate, trim and crop an image

Use this when the photo is sideways or has unwanted borders. All three are \includegraphics options:

\includegraphics[width=0.4\textwidth, angle=90]{photo.jpg} % rotate 90° anticlockwise
\includegraphics[trim=2cm 1cm 2cm 1cm, clip, width=0.5\textwidth]{photo.jpg} % crop
  • angle= rotates anticlockwise by the given degrees.
  • trim=left bottom right top removes that much from each edge.
  • clip hides the trimmed parts. Without it, trim only changes the space LaTeX reserves.

Position the image with the figure environment

Use this when the image needs a caption, a number, or a sensible place on the page. A figure is a float: LaTeX moves it to avoid half-empty pages.

\begin{figure}[htbp]
\centering
\includegraphics[width=\textwidth]{example.jpg}
\caption{An example image.}
\label{fig:example}
\end{figure}

JPG image inside a LaTeX figure environment with a numbered caption below it

The letters in square brackets say where LaTeX may place the figure:

SpecifierMeaning
hHere, roughly where it appears in the source
tTop of a page
bBottom of a page
pOn a separate page of floats
!Relax LaTeX’s internal limits, used with others ([!ht])
HExactly here, no floating (needs \usepackage{float})

[htbp] is a good default because it gives LaTeX every option. For fine-tuning, see Overleaf’s guide to positioning images and tables.

Align an image left, right or centre

Use this to change horizontal alignment inside a figure. Put the command at the start of the figure:

  • \centering centres the image and caption.
  • \raggedright aligns them left.
  • \raggedleft aligns them right.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{example.jpg}
\caption{A centred image.}
\label{fig:centered}
\end{figure}

Centred JPG image with its caption in a LaTeX figure

Outside a figure, use \begin{center}…\end{center} around the \includegraphics call. Avoid center inside a figure; it adds extra vertical space.

Add captions and labels

Use this when you’ll refer to the image from the text. \caption numbers the figure, and \label gives it a name you can reference.

  1. Put \caption{…} below the image for a caption underneath, or above it for a caption on top.
  2. Put \label{fig:name} directly after \caption. A label placed before the caption picks up the section number instead.
  3. Refer to it with Figure~\ref{fig:name}, and compile twice.
\begin{figure}[htbp]
\centering
\caption{This caption appears above the image.}
\label{fig:example2}
\includegraphics[width=0.8\textwidth]{example.jpg}
\end{figure}
As shown in Figure~\ref{fig:example2}, the results indicate...

LaTeX figure with the caption placed above the image

Tables work the same way; see how to reference figures and tables with \ref, including \autoref and \cref.

Wrap text around an image with wrapfig

Use this when a small image should sit beside a paragraph with text flowing around it. Load \usepackage{wrapfig}, then put the image in a wrapfigure placed just before the paragraph.

\begin{wrapfigure}{r}{0.4\textwidth}
\centering
\includegraphics[width=0.38\textwidth]{example.jpg}
\caption{Example image with wrapped text.}
\label{fig:wrapexample}
\end{wrapfigure}
  • {r} puts the image on the right; {l} puts it on the left.
  • {0.4\textwidth} is the width reserved for the image. Make the image slightly narrower.

Paragraph text wrapping around a JPG image placed on the right with wrapfig

The optional first argument is the number of text lines to wrap, which helps when wrapfig guesses wrong. It must be a number:

\begin{wrapfigure}[12]{r}{0.4\textwidth}
\vspace{-10pt} % pull the image up slightly
\centering
\includegraphics[width=0.38\textwidth]{example.jpg}
\caption{Adjusted spacing example.}
\label{fig:wrapspacing}
\end{wrapfigure}

Warning: wrapfig doesn’t work inside lists, and wrapping goes wrong if a heading or very short paragraph follows. Start the wrapfigure just before a long plain paragraph.

Wrapping text inside table cells is a different job; see how to wrap text inside table cells. The wrapfig documentation on CTAN lists every option.

Put images side by side with subcaption

Use this for two or more related images, each with its own (a), (b) caption. The subcaption package is the current standard.

\usepackage{subcaption} % in the preamble
\begin{figure}[htbp]
\centering
\begin{subfigure}{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{image1.jpg}
\caption{First image.}
\label{fig:sub1}
\end{subfigure}
\hfill
\begin{subfigure}{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{image2.jpg}
\caption{Second image.}
\label{fig:sub2}
\end{subfigure}
\caption{Overall caption for the figure with subfigures.}
\label{fig:multi}
\end{figure}

Result: two images on one row, captioned (a) and (b), with one overall figure caption.

Two JPG images side by side, each with its own sub-caption and one shared figure caption

Older tutorials use the subfig package’s \subfloat. It still works, but don’t load subfig and subcaption together; they conflict.

If you don’t need sub-captions, two minipage environments do the same job:

\begin{figure}[htbp]
\begin{minipage}{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{example1.jpg}
\caption{First image.}
\label{fig:first}
\end{minipage}
\hfill
\begin{minipage}{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{example2.jpg}
\caption{Second image.}
\label{fig:second}
\end{minipage}
\end{figure}

Which method should you use?

MethodBest forPackage
\includegraphics aloneInline images with no captiongraphicx
figure environmentNumbered images with captionsBuilt in
figure with [H]Images that must not movefloat
wrapfigureSmall images with text flowing aroundwrapfig
subfigureSeveral related images with (a), (b) captionssubcaption

Using images in Overleaf

The commands are identical in Overleaf. The only extra step is getting the file into the project:

  1. Upload the JPG with the upload button in the file tree, or drag it onto the file tree.
  2. If you put it in a folder, add \graphicspath{{folder/}} or include the folder in the path.
  3. Recompile.

Common errors

  • “File ‘photo.jpg’ not found”: check the spelling, the letter case (Overleaf and Linux are case-sensitive) and the folder. Spaces in file names can also cause trouble; rename the file.
  • “Cannot determine size of graphic … (no BoundingBox)”: you’re compiling with plain latex. Switch to pdfLaTeX, XeLaTeX or LuaLaTeX.
  • The image runs past the margin: add width=\linewidth or a fraction of it.
  • The figure jumps to another page: use [htbp], shrink the image, or use [H] with the float package.
  • “Missing number, treated as zero” at a wrapfigure: the optional argument must be a number of lines, such as [12], not text.
  • \ref prints the section number: move \label after \caption.

The graphicx package page on CTAN has the full option list. For more figure, table and code tutorials, browse the LaTeX guides.

Working in Word instead? See how to place an image beside text in Word. And if a collaborator needs an editable copy, you can convert your LaTeX file to Word once the figures are in place.

Frequently asked questions

Why does my image appear on a different page in LaTeX?

A figure environment is a float, so LaTeX moves it to where it fits best. Use [htbp] to allow more positions, or load the float package and use [H] to keep the figure exactly where it is in the source.

Can I use a JPG image with the latex (DVI) compiler?

No. Plain latex cannot read the size of a JPG and stops with a "Cannot determine size of graphic" error. Compile with pdfLaTeX, XeLaTeX or LuaLaTeX, or convert the image to EPS.

How do I keep an image's aspect ratio in LaTeX?

Set only width or only height, and graphicx scales the other dimension to match. If you set both, add keepaspectratio so the image fits inside that box without stretching.

How do I put two images side by side in LaTeX?

Place two subfigure environments from the subcaption package inside one figure, each about 0.48\textwidth wide, separated by \hfill. Two minipage environments work the same way if you do not need sub-captions.

Where should I put image files for a LaTeX document?

Put them in the same folder as the .tex file, or in a subfolder and add \graphicspath{{images/}} to the preamble. In Overleaf, upload the image to the project first; the same commands then work.