Skip to content

At time, it might be desirable to wrap text around a float (a figure, in our case) so as not to break the flow of the text. There are a number of packages in LaTeX to accomplish this task, though they requires some amount of manual tuning in most of the cases.

Using wrapfig

To use wrapfig, we need to include the following line in preamble -

\usepackage{wrapfig}

This makes the wrapfigure environment available to us, and we can put a \includegraphics command inside it to create a figure around which text will be wrapped. Here is how we can specify a wrapfigure environment -

\begin{wrapfigure}[lineheight]{position}{width}
  ...
\end{wrapfigure}


The position parameter has eight possible values -

r R right side of the text
l L left side of the text
i I inside edge–near the binding (in a twoside document)
o O outside edge–far from the binding

The uppercase version allows the figure to float. The lowercase version means exactly here.

Here is an example -

\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \includegraphics[width=0.48\textwidth]{birds}
  \end{center}
  \caption{Birds}
\end{wrapfigure}

It may be noted that the width of the image included was specified relative to width of the text (\textwidth). It is a good idea to use relative sizes to define lengths (height, width, etc), particularly when using wrapfigure.

In the example above, the figure covers exactly half of the the textwidth, and the actual image uses a slightly smaller width, so that there is a pleasing small white frame between the image and the text. The image should always be smaller (less wide) than the wrap, or it will overrun the text.

Take care while using adding wrapfigures very near the top or bottom of a page, as this can often cause unwanted effects that are hard or near-impossible to solve. It is not advisable to try to use wrapfigures alongside equations or sectional headers. They also cannot be used in lists, such as itemize and enumerate environments.

Dealing with Images with white space

In case the image has undesirable white space, we can use any of the following options to remove the extra whitespace -

  • trim the white space when using \includegraphics
  • The picins package may be used instead of wrapfigure, which removes the extra white space out of the box without any manual tuning.
  • The package floatflt is another alternative.
  • Avoid using \begin{center} to center the image, it adds extra space. Use \centering instead.
  • The program pdfcrop (included in most tex installations) may be used to remove the white space permanently.

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX