How to Insert an Image in LaTeX
Load \usepackage{graphicx} and write \includegraphics[width=0.8\linewidth]{photo.png}. To number the image and give it a caption, put it in a figure environment with \caption{…} and \label{fig:photo}, then refer to it with \ref{fig:photo}.
Image commands
- Text mode, no math preview
\usepackage{graphicx}Preamble: enables
\includegraphics. - Text mode, no math preview
\includegraphics{file.png}Insert the image at its natural size.
- Text mode, no math preview
\includegraphics[width=0.5\linewidth]{file}Half the text width; height scales with it.
- Text mode, no math preview
\includegraphics[scale=0.4, angle=90]{file}Scale and rotate.
- Text mode, no math preview
\begin{figure}[htbp] ... \end{figure}Floating figure with caption and number.
- Text mode, no math preview
\graphicspath{{images/}}Folder where LaTeX looks for images.
Try it live
Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.
Insert an image examples
Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.
A formula you might caption
LaTeXy = e^{-x^2/2}Reference to a figure in a formula context
LaTeX\text{see Figure 2: } \lim_{n \to \infty} a_n = 0
In a LaTeX document
These commands work in the text of a .tex document (Overleaf, TeX Live, MiKTeX), not inside math. The box on the right shows what the compiled PDF looks like.
Figure with caption and label
LaTeX\usepackage{graphicx} ... \begin{figure}[htbp] \centering \includegraphics[width=0.7\linewidth]{results.png} \caption{Measured values and the fitted curve.} \label{fig:results} \end{figure} Figure~\ref{fig:results} shows the fit.Two images side by side
LaTeX\usepackage{subcaption} ... \begin{figure}[htbp] \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{The sample before and after.} \end{figure}Image exactly here, not floating
LaTeX\usepackage{float} ... \begin{figure}[H] \centering \includegraphics[width=0.5\linewidth]{diagram.pdf} \caption{Setup.} \end{figure}
File formats
pdfLaTeX, XeLaTeX and LuaLaTeX (Overleaf's engines) accept PNG, JPG and PDF. Use PDF or SVG converted to PDF for diagrams and plots so they stay sharp, and PNG for screenshots. EPS works with LaTeX + dvips, or with pdfLaTeX through automatic conversion.
Leave out the extension (\includegraphics{results}) and LaTeX picks the best format it finds. Avoid spaces and extra dots in file names.
Placement
A figure floats: LaTeX moves it to where it fits best, which is why it may not appear exactly where it is in the source. The option [htbp] allows here, top, bottom or a float page. [H] from the float package forces "exactly here". Refer to figures by number (Figure~\ref{…}) instead of "below".
For a picture of an equation, consider not using an image at all: the image to LaTeX converter on this site turns a screenshot of it into real, editable LaTeX.
Common mistakes
"Undefined control sequence" until the package is loaded.
Instead of\includegraphics{photo.png} (no graphicx)Write\usepackage{graphicx}The label must come after the caption, or
\refprints the section number.Instead of\label{fig:a}\caption{…}Write\caption{…}\label{fig:a}Spaces and extra dots in file names can stop the image from loading.
Instead of\includegraphics{My Photo.v2.png}Write\includegraphics{my-photo-v2.png}
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
Upload the image with the Upload button, then reference it by its path in the project. Overleaf supports PNG, JPG, PDF and EPS.
MathJax and KaTeX
Web math renderers cannot include images; on a web page use an HTML
imgelement next to the formula.Microsoft Word
In Word use Insert › Pictures, then References › Insert Caption for numbered figures.
Already have the whole document?
Move complete papers between PDF, Word and LaTeX without retyping; every equation stays editable.
- PDF to LaTeXTurn a paper or textbook PDF into a .tex project with every equation.10 credits per page
- Word to LaTeXA .docx with Word equations becomes LaTeX ready for Overleaf.10 credits per page
- LaTeX to WordA whole .tex file becomes a .docx whose equations open in Word.5 credits per file
Single printed formulas are free: 3 a day without an account, 6 with a free account. New accounts get 30 credits to try handwriting, pages and documents; failed conversions return their credits. See plans and credit prices.
Insert an image in LaTeX: questions
- How do I insert an image in LaTeX?
- Load graphicx and write
\includegraphics[width=\linewidth]{file}. - Why is my image not where I put it?
- Figures float. Use
[htbp], or[H]with the float package to fix the position. - How do I put two images side by side?
- Use two subfigure environments of width 0.48\linewidth inside one figure (subcaption package).
- How do I resize an image?
- Give a width (
width=0.5\linewidth), a height or a scale in the options.
Related LaTeX reference
- How to Start a New Page in LaTeX\newpage, \clearpage, \cleardoublepage and \pagebreak compared, floats, blank pages and breaks inside long equations.
- How to Make a LaTeX TableThe tabular environment: column alignment, borders, merged cells, booktabs rules, captions, plus array for tables inside math.
- How to Add a Hyperlink in LaTeXhyperref's \href for linked text, \url for printed addresses, internal links to sections and figures, and link colors.
- How to Use LaTeXFrom zero to a compiled document: where to write, the minimal file, text, math, lists, tables, images and reading errors.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
Have the formula as a picture?
Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.
Convert an image to LaTeX