63

How to text-wrap an image in LaTeX.

Ex: In technical documents, authors names will be text wrapped tights, with their images.

Martin Scharrer
  • 262,582

2 Answers2

91

Just to add another answer here in case anyone else has this question - you can wrap text around figures quite nicely with the wrapfig package. Here's a short example showing left and right aligned images with captions, with the text wrapped around.

This example is also viewable on Overleaf if you want to see the pdf output next to the code.

\documentclass[a4paper]{article}

\usepackage[english]{babel} \usepackage{graphicx} \usepackage{wrapfig}

\title{Package Example: wrapfig} \author{writeLaTeX}

\begin{document} \maketitle

\begin{wrapfigure}{R}{0.3\textwidth} \centering \includegraphics[width=0.25\textwidth]{frog.jpg} \caption{\label{fig:frog1}This is a figure caption.} \end{wrapfigure}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.

\begin{wrapfigure}{L}{0.3\textwidth} \centering \includegraphics[width=0.25\textwidth]{frog.jpg} \caption{\label{fig:frog2}This is a figure caption.} \end{wrapfigure}

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.

Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu massa.

\end{document}

How it looks:

Text wrapped around an image using the wrapfig package

Edit: Meant to add a note to say I'm one of the developers of Overleaf (formerly WriteLaTeX), and any feedback is appreciated! Thanks :-)

  • thank you for your anwswer. I was looking for a way to do this in LaTeX.

    Just one question, in case you know: wrapfig documentation says that wrapped figures may be wrongly ordered when listed together with regular floats. Do you know a solution for that?

    – Vicent Apr 12 '14 at 17:33
  • 3
    You should replace “writeLaTeX” by “overleaf”… – yannis Dec 26 '14 at 10:53
  • Thanks for the heads up Yannis, yes, we have a fair few things to change. For info, the company name is still Writelatex, so it is still applicable, just not front-and-center anymore. – John Hammersley Dec 27 '14 at 22:37
  • I get the picture overlapped with the text :( – Twink Sep 30 '17 at 22:43
  • I get the picture overlapped with the text too. It also adds this paragraph in latin to the text : "Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbiauctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricieset, tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquetmagna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis.Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociisnatoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.Aliquam tincidunt urna. " – Masih Oct 31 '20 at 01:23
  • Thanks for reporting this, it looks like it's caused by a recent(ish) update to the lipsum package, which breaks something about lists/paragraphs. Lian Tze has fixed and updated the example at https://www.overleaf.com/latex/examples/package-example-wrapfig/hmdrphhbxmjp (fixed by removing the lipsum package and using manual blocks of text instead). Does that help? – John Hammersley Nov 02 '20 at 09:57
  • 1
    This is a very good solution, but I would like it to be more tightly wrapped below the caption. Is there a way of controlling this? Edit: I found this which solved it for me https://tex.stackexchange.com/questions/31764/white-space-under-wrapfigure-caption – Beth Long Apr 14 '23 at 23:55
20

Since author names are usually not that long that it could used as text to wrap around their images, I think you want to put the images inside text mode?

That can be done with \includegraphics that does not depend on environment figure or similar. Also there are many ways for scaling an image, the image can be rotated and positioned differently. The following example scales the image that it fits inside a line (\baselineskip. 30% is taken for the depth and 70% for the height of the image, values taken from \strut).

Example file:

\documentclass{article}
\usepackage{graphicx}

\newcommand*{\authorimg}[1]{%
  \raisebox{-.3\baselineskip}{%
    \includegraphics[
      height=\baselineskip,
      width=\baselineskip,
      keepaspectratio,
    ]{#1}%
  }%
}

\begin{document}
\begin{itemize}
\item[\authorimg{PeterM_Foxhead.png}] Author of Firefox
\item[\authorimg{Andy_ant.png}] Author of Apache Ant
\end{itemize}
\end{document}

Result

The images are taken from Openclipart:

Heiko Oberdiek
  • 271,626