Learn how to wrap an image with text in LaTeX


In LaTeX, by default, when inserting an image as a floating object it will be inserted and printed as its own paragraph. However, in certain kinds of documents, like news articles, this is not the kind of behavior we want to see, since it is conventional to leave the minimum blank space along with the page, and therefore the text is commonly wrapped around images. In this tutorial, we are going to explain how to do so inside a LaTeX document.

Wrapfig package — Produces figures where text can flow around

For this purpose, we will use the wrapfig external packageOpens in a new tab. and its environment wrapfigure. This environment behaves essentially as a floating figure environment, but it takes two additional mandatory arguments:

  • The first, specifies the position parameter and,
  • The second, the width that the whole environment will take up.

The position parameter specifies in which position inside the text contents the figure will be placed. The values this argument can take are:

  • r to put the image at the right side of the text,
  • l to put it at the left side, and,

For two-column documents,

  • i to put it in the inside edge (near the binding) and
  • o to put it in the outside edge (far from the binding).

The following example illustrates how to wrap images easily in LaTeX:

% Wrap image (figure) with text
\documentclass{article}

\usepackage{wrapfig}
\usepackage{graphicx}

% For dummy text
\usepackage{blindtext}

\begin{document}

\begin{wrapfigure}{r}{0.4\textwidth}
\centering
    \includegraphics[width=0.35\textwidth]{img1.jpg}
    \caption{This is a figure positioned at the right and wrapped with text.}
    \label{fig:img1}
\end{wrapfigure}

\blindtext

\begin{wrapfigure}{l}{0.35\textwidth}
    \centering
    \includegraphics[width=0.3\textwidth]{nature2}
    \caption{This is a figure positioned at the left and wrapped with text .}
    \label{fig :img2}
\end{wrapfigure}

\blindtext
\blindtext

\end{document}

Compiling this code yields the following output:

Wrap image with text in LaTeX

You can download images from the links: img1Opens in a new tab., nature 2Opens in a new tab..

In this example, we loaded the package blindtextOpens in a new tab. simply to produce dummy text with the command \blindtext. Also, the graphicx packageOpens in a new tab. is needed to use the \includegraphics command to insert the images.

We reached the end of this short tutorial, If you have any remarks or suggestions, please feel free to reach us via email at admin@latex-tutorial.comOpens in a new tab.

Recent Posts