The wrapfig package
Lets text flow around a narrow figure or table at the edge of the page: the environments wrapfigure and wraptable.
Loading the package
\usepackage{wrapfig}A normal figure takes the full width of the text. wrapfigure puts the image at the left or right edge and shortens the lines of the following paragraphs beside it. Its two required arguments are the side (r or l) and the width of the area reserved for the image.
Start the environment between two paragraphs, directly before the text that should wrap. LaTeX estimates from the height of the image how many lines to shorten; an optional first argument sets that number by hand. \caption works inside the environment and counts with the normal figures.
Main commands
\begin{wrapfigure}{r}{0.4\textwidth} ... \end{wrapfigure} | Image at the right edge in an area of 40 % of the text width. |
\begin{wrapfigure}{l}{5cm} | Image at the left edge. |
\begin{wrapfigure}[8]{r}{5cm} | Shortens exactly 8 lines, for the case that the automatic count leaves a gap or overlaps. |
\begin{wrapfigure}{R}{5cm} | A capital letter lets the image move to a later position when it does not fit here. |
\begin{wraptable}{r}{5cm} ... \end{wraptable} | The same for a small table, with a table caption. |
Complete example
\documentclass{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
\begin{wrapfigure}{r}{0.4\textwidth}
\centering
\includegraphics[width=0.38\textwidth]{image.png}
\caption{The text flows around this image.}
\end{wrapfigure}
This paragraph starts next to the image. Its lines are shorter
than the lines of a normal paragraph, because the right part of
the text area is reserved. The reserved area ends below the
caption. From there on the lines use the full width again, and
the paragraph continues without a visible break. The text has to
be long enough to reach the lower edge of the image; a paragraph
that ends too early leaves the following heading or list beside
the image as well. This sentence adds the lines that are needed
to show the return to the full width in this example.
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- Inside a list such as
itemize, and directly before or after one, the environment does not work. The log shows the warning "wrapfigure used inside a conflicting environment". - Too little text beside the image pulls the next heading, list or page break into the wrapped area. Move the environment to a longer paragraph or set the number of lines by hand.
- A
wrapfigureis not a float. It can appear in a different order than thefigureenvironments around it, and it should not sit next to a page break.
Related pages
- How-to Wrap text around an image in LaTeX
- How-to Insert an image in LaTeX
- Package
graphicx - Package
caption