How to Insert an Image in LaTeX
To insert an image in LaTeX, load graphicx and write \includegraphics[width=0.6\linewidth]{photo}, where photo is the file name. Put it inside a figure environment to add a numbered caption.
\begin{figure}[h]
\centering
\includegraphics[width=0.6\linewidth]{example-image}
\caption{A sample image at 60\% of the line width}
\label{fig:sample}
\end{figure}Needs \usepackage{graphicx} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\includegraphics[width=0.6\linewidth]{example-image}
\caption{A sample image at 60\% of the line width}
\label{fig:sample}
\end{figure}
\end{document}example-image is a test picture from the mwe package, so the code compiles as is. Replace it with your own file name.
Where should the image file be?
In the same folder as the .tex file, or in a subfolder you name in the path: {images/photo}. To search a folder by default, add \graphicspath{{images/}} to the preamble. You can leave out the extension; LaTeX tries the formats it knows. Avoid spaces in file names. On Overleaf, upload the file to the project first; the same path rules apply.
How do you change the image size?
Give one dimension and the other follows, keeping the proportions. width=0.5\linewidth makes the image half as wide as the text, height=2cm sets a fixed height, and scale=0.5 shrinks it to half its own size. Setting both width and height stretches the image unless you add keepaspectratio.
\includegraphics[height=2cm]{example-image-a}
\includegraphics[scale=0.15]{example-image-b}
\includegraphics[width=2cm, angle=90]{example-image-c}Needs \usepackage{graphicx} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[height=2cm]{example-image-a}
\includegraphics[scale=0.15]{example-image-b}
\includegraphics[width=2cm, angle=90]{example-image-c}
\end{document}How do you crop an image in LaTeX?
Use trim=left bottom right top together with clip. The four numbers are cut from each edge, in points of the original image unless you give units such as 1cm. Without clip, the trimmed parts still show and only the spacing changes.
Full image: \includegraphics[width=3cm]{example-image}
\quad Cropped:
\includegraphics[width=3cm, trim=60 40 60 40, clip]{example-image}Needs \usepackage{graphicx} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{graphicx}
\begin{document}
Full image: \includegraphics[width=3cm]{example-image}
\quad Cropped:
\includegraphics[width=3cm, trim=60 40 60 40, clip]{example-image}
\end{document}Which image formats does LaTeX accept?
| Engine | Formats |
|---|---|
pdflatex, xelatex, lualatex | PDF, PNG, JPG; EPS is converted to PDF automatically in current TeX Live |
latex (DVI output) | EPS |
SVG isn't read directly. Export it to PDF, or use the svg package, which calls Inkscape and needs --shell-escape.
Why doesn't the image stay where I put it?
A figure is a float, and LaTeX moves it to avoid gaps on the page, as the page break guide explains. To put two images next to each other with (a) and (b) labels, see subfigures. For an image of a formula, the LaTeX to PNG tool makes one in your browser. For a sharp vector image of a formula, use LaTeX to SVG.
Sources
- graphicx package documentation, Packages in the graphics bundle (CTAN), read Nov 28, 2026
- mwe package documentation (CTAN), read Nov 28, 2026
- svg package documentation (CTAN), read Nov 28, 2026
Text drafted with AI from the graphicx documentation; every example compiled with TeX Live 2026; checked by Cem Demir. See the editorial policy.