How to Insert and Position Images in LaTeX
To add an image in LaTeX, load graphicx and use \includegraphics inside a figure environment. Control placement with float specifiers h, t, b, and p.
To add an image in LaTeX, load the graphicx package and use \includegraphics[width=...]{filename} inside a figure environment. The figure environment gives the image a caption, an auto-incrementing number, and a label you can reference. LaTeX then floats the figure to the best nearby position.
1. The standard figure block
\usepackage{graphicx} % in the preamble
...
\begin{figure}[t]
\centering
\includegraphics[width=0.8\linewidth]{diagram.png}
\caption{System architecture overview.}
\label{fig:arch}
\end{figure}
Set the size relative to the text width (width=0.8\linewidth) rather than in centimetres, so the figure scales correctly across page geometries. Reference it with Figure~\ref{fig:arch}.
2. Control where it lands
The optional argument after figure is a placement hint, not a command. LaTeX treats figures as floats to avoid awkward page breaks.
| Specifier | Meaning |
|---|---|
| h | Here, approximately |
| t | Top of a page |
| b | Bottom of a page |
| p | On a dedicated float page |
| ! | Ignore LaTeX's strict spacing rules |
| H | Exactly here (requires the float package) |
Combine them — [htbp] gives LaTeX the most freedom and prevents "too many unprocessed floats" errors.
3. Resize, rotate, and crop
\includegraphics accepts useful options:
\includegraphics[width=5cm]{a.png} % fixed width
\includegraphics[height=4cm]{a.png} % fixed height
\includegraphics[scale=0.5]{a.png} % half size
\includegraphics[angle=90]{a.png} % rotate 90°
\includegraphics[width=\linewidth, trim=10 10 10 10, clip]{a.png} % crop
Set a default search folder with \graphicspath{figures/} so you don't repeat the path on every image.
4. Side-by-side images
Use subcaption for two panels with their own captions:
\usepackage{subcaption}
...
\begin{figure}[t]
\centering
\begin{subfigure}{0.48\linewidth}
\includegraphics[width=\linewidth]{before.png}
\caption{Before}\label{fig:before}
\end{subfigure}\hfill
\begin{subfigure}{0.48\linewidth}
\includegraphics[width=\linewidth]{after.png}
\caption{After}\label{fig:after}
\end{subfigure}
\caption{Comparison of the two states.}
\end{figure}
5. Vector diagrams without an image file
For schematics, flowcharts, and plots, draw natively with TikZ so the graphics scale perfectly and match your fonts — see How to Draw Diagrams in LaTeX With TikZ. Pair figures with captioned tables and reference both with the cross-referencing guide.
→ Drag-drop images and see them placed instantly in LetX. Writing a full paper? See How to Write a Research Paper in LaTeX.
Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs, maker of LetX.
Frequently Asked Questions
Why does my LaTeX image appear on a different page than where I put it?
Because a figure is a float — LaTeX moves it to wherever it fits best, not necessarily where you typed it. Influence placement with the optional specifier: [t] top, [b] bottom, [h] here, [p] float page, and [!] to override LaTeX's aesthetic limits. Use [htbp] to give LaTeX several options. To force a figure exactly in place, load the float package and use [H], but use it sparingly because it can leave large gaps.
What image formats can LaTeX use?
With pdfLaTeX, the default compiler, you can include PDF, PNG, and JPG files directly. Vector formats (PDF, and SVG converted to PDF) stay sharp at any zoom and are best for plots and diagrams; PNG suits screenshots; JPG suits photos. The older latex+dvips route required EPS. If you have an EPS file, convert it to PDF with epstopdf, which most distributions run automatically.
How do I place two images side by side in LaTeX?
Use the subcaption package and two subfigure environments inside one figure, each about 0.48\linewidth wide, so they sit on the same line with individual captions and labels like Figure 1a and 1b. Alternatively, place two \includegraphics commands in a single centered line with a small \hspace between them if you don't need sub-captions.