Figures and Images

Inserting Images in LaTeX: PDF, PNG and More

Learn how to insert PDF, PNG, JPG and EPS images in LaTeX with graphicx, including Overleaf uploads, file formats, sizing and common errors.

On this page
  1. What you need: the graphicx package
  2. Insert a PDF image in Overleaf
  3. Image formats and which engine reads them
  4. Set the size and crop
  5. Wrap the image in a figure with a caption
  6. Organize image files
  7. Common errors and fixes

To insert a PDF image in Overleaf, upload the file to your project, load the graphicx package, and call \includegraphics with the file name. On your own computer the steps are the same, except the image has to sit in the folder where you compile the .tex file. The rest of this guide covers which formats work, how to size an image, and what to do when it doesn’t appear.

What you need: the graphicx package

Every example here uses the graphicx package. Load it once in the preamble:

\documentclass{article}
\usepackage{graphicx}

graphicx provides \includegraphics, the command that places an image file on the page. It doesn’t add captions or numbering. For those, you wrap the image in a figure environment, as shown below.

Insert a PDF image in Overleaf

  1. Use the upload option in the file panel and choose your PDF. Drag and drop usually works too.
  2. Wait for the upload to finish. The file appears in the file tree.
  3. Add the command where the image should appear:
\includegraphics[width=0.8\linewidth]{my-diagram}

You can leave out the .pdf extension, and LaTeX finds my-diagram.pdf. If two files share a base name, such as plot.pdf and plot.png, write the extension to pick the one you want.

  1. Compile the project. The image appears where the command sits.

Image formats and which engine reads them

The LaTeX engine decides which formats you can include. Most projects use pdfLaTeX, and the table assumes it.

Format Works directly with pdfLaTeX Notes
PDF Yes Good for vector drawings and plots. Use page= to pick a page from a multi-page PDF.
PNG Yes Raster image. Transparent areas stay see-through if the file has an alpha channel. See the transparent images guide.
JPG Yes Raster image, suited to photos. JPG has no transparency.
EPS No Convert to PDF first, or use the classic latex and dvips route.
SVG No Convert with Inkscape, or use the svg package.

XeLaTeX and LuaLaTeX also don’t read EPS directly. The classic latex command produces DVI output, so it follows a different path. It reads EPS through dvips, and it needs extra steps for PNG and JPG. If you work with EPS files, see the guide to EPS images and bounding box errors. For SVG, see the guide to SVG images with Inkscape.

Set the size and crop

\includegraphics accepts options in square brackets. The most useful ones are:

  • width, height and scale set the size. Setting only width keeps the aspect ratio.
  • angle rotates the image.
  • trim and clip crop it. trim=left bottom right top removes margins, and clip hides anything outside the frame.
\includegraphics[width=\linewidth, trim=10mm 5mm 10mm 5mm, clip]{plot}

In a single-column document, \linewidth equals the text width. Inside a minipage or a subfigure, it equals the width of that box.

A PDF’s page size becomes its image size. If the file has wide margins, crop it first with a tool such as pdfcrop, or use trim and clip.

Wrap the image in a figure with a caption

Use the figure environment to get a number, a caption and a label you can refer to:

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.7\linewidth]{my-diagram}
  \caption{Architecture of the test rig.}
  \label{fig:rig}
\end{figure}

In the text, write As Figure~\ref{fig:rig} shows. The ~ keeps the number attached to the word “Figure”. The [htbp] argument tells LaTeX where it may place the figure. The guide to controlling figure placement explains each option.

When several images need one caption, put them in subfigures. The subfigures guide covers that layout. If you want text to run beside an image instead of around a float, see how to wrap text around an image.

Organize image files

As a project grows, keep the images in a folder such as images/. You have two options.

Write the folder in each command:

\includegraphics{images/my-diagram}

Or set a graphics path once in the preamble:

\graphicspath{{images/}}

With that line, \includegraphics{my-diagram} finds images/my-diagram.pdf. The double braces are required.

Avoid spaces and special characters in file names. A space can break the path, and LaTeX then reports a missing file. Match the case of each name exactly, because some systems treat Plot.pdf and plot.pdf as different files.

Common errors and fixes

  • File 'x.pdf' not found. Check the spelling, the folder path and the exact file name. Confirm the upload finished.
  • Unknown graphics extension: .eps. pdfLaTeX can’t read EPS directly. Convert the file or use the classic route, as explained in the EPS guide.
  • Cannot determine size of graphic ... (no BoundingBox). The EPS file has no usable bounding box. The same guide shows how to fix it.
  • The image is too large or cut off. Set width or scale, or crop with trim and clip.
  • An SVG doesn’t appear. LaTeX doesn’t read SVG files directly, so convert the file first. The SVG guide covers the three options.

Once the image appears, the next step is usually placement. If a figure keeps moving away from the text where you wrote it, the placement guide explains the specifiers and the H option.

Keep exploring

Guides from other topics

All topics →