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]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]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]Pitfalls
wrapfiguredoes not work inside lists such asitemizeandenumerate. The log then shows the warning "wrapfigure used inside a conflicting environment".- Check the result near a page break and before a section heading.
wrapfigshortens lines until its line count is used up, also on the next page or next to the heading. - In a
twosidedocument,iandoput the image at the inner or outer edge of the page.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
wrapfig - Package
graphicx - How-to Insert an image in LaTeX
- How-to Place content side by side in LaTeX
- How-to Figure placement in LaTeX
- Package
lipsum