TransWikia.com

How to text-wrap an image in LaTeX

TeX - LaTeX Asked by Udhay Prakash on January 5, 2021

How to text-wrap an image in LaTeX.

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

2 Answers

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{-.3baselineskip}{%
    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:

Answered by Heiko Oberdiek on January 5, 2021

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.3textwidth}
centering
includegraphics[width=0.25textwidth]{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.3textwidth}
centering
includegraphics[width=0.25textwidth]{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 :-)

Answered by John Hammersley on January 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP