Wrap text around an image in LaTeX (wrapfigure)

The wrapfigure environment from the wrapfig package puts an image at the left or right edge of the text block and lets the following paragraph run past it.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}

Put an image at the right edge

The two arguments are the side (r for right, l for left) and the width of the space that is kept free. Write the environment directly before the paragraph that wraps around it. \lipsum[1] from the lipsum package stands for a paragraph of text here.

\begin{wrapfigure}{r}{0.4\textwidth}
\centering
\includegraphics[width=0.38\textwidth]{image.png}
\caption{The measurement setup}
\end{wrapfigure}
\lipsum[1]
Result
The compiled example

Set the number of short lines

wrapfig computes from the height of the image how many lines it shortens. When the gap below the image is too large or the text runs into it, set the number in the first optional argument: [8] shortens eight lines.

\begin{wrapfigure}[8]{l}{0.3\textwidth}
\includegraphics[width=\linewidth]{image.png}
\end{wrapfigure}
\lipsum[2]
Result
The compiled example

Let the image stick out into the margin

The optional argument after the side is the overhang: {r}[1cm]{0.4\textwidth} moves the image 1 cm into the right margin, and the text gains that width.

\begin{wrapfigure}{r}[1cm]{0.4\textwidth}
\includegraphics[width=\linewidth]{image.png}
\end{wrapfigure}
\lipsum[3]
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages