6

I need to add a long image to the side of the document, but the text does not seem to be wrapping around the image.


\documentclass[letterpaper,12pt]{report}
\usepackage{subfigure}
\usepackage{float}
\usepackage{graphicx}
\usepackage{lipsum}

\usepackage{wrapfig}

\begin{document} \section{sec1} \lipsum[1-4]

\subsection{subsec1}

\begin{wrapfigure}{r}{5.5cm} \label{wrap-fig:1} % \includegraphics[height=15cm]{sample} \rule{5cm}{15cm} \caption{A wrapped figure going nicely inside the text.} \end{wrapfigure}

\lipsum[5]

\section{sec2} \lipsum[5-12]

\end{document}

How can I wrap the image properly?

weasel
  • 257
  • 2
    Unrelated to the issue, but \label has to be put either inside the argument of \caption or after \caption (the optimum is inside the argument). – Skillmon Mar 19 '21 at 08:49
  • You might consider using paracol instead of wrapfigure. See https://tex.stackexchange.com/questions/586554/collision-between-wrapping-environments/586676?r=SearchResults&s=1|0.0000#586676 for example. – John Kormylo Mar 19 '21 at 13:22

2 Answers2

5

The problem does not seem to be the wrapfigure itself, but somehow \lipsum text does not behave and interact with it like regular text would.

If you use e.g \blindtext instead, you will get the expected wrapping:

\documentclass[letterpaper,12pt]{report}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{blindtext}

\usepackage{wrapfig}

\begin{document} \section{sec1} \blindtext[4]

\subsection{subsec1}

\begin{wrapfigure}{r}{5.5cm}
    \centering
    \includegraphics[height=15cm,width=5cm]{example-image}
    \caption{A wrapped figure going nicely inside the text.}
    \label{wrap-fig:1}
\end{wrapfigure} 
\blindtext


\section{sec2}
\blindtext[6]

\end{document}

enter image description here

schoekling
  • 3,142
  • Except, of course, that you will need to adjust the number of lines (optional) to handle the extra space. – John Kormylo Mar 19 '21 at 13:18
  • Which is behavior to be expected from wrapfigures. An explanation on how to deal with the number of lines can be found here. – schoekling Mar 19 '21 at 13:29
  • I am using \lipsum here in place of my actual text, which is having the same behaviour. Sounds like it is a problem with \wrapfig then? – weasel Mar 22 '21 at 03:50
  • In that case, I cannot reproduce your problem. For me using \blindtext or inserting actual text wraps as I've shown in my answer. I am guessing some other packages not included in your MWE are to blame. Have you tried inserting your specific text into the code from my answer? – schoekling Mar 22 '21 at 09:04
1

Using \vspace with a negative margin before \end{wrapfigure} fixes the problem, although this probably doesn't get to the root of it.

\begin{wrapfigure}{r}{5.5cm}
  \label{wrap-fig:1}
    \rule{5cm}{15cm}
  \caption{A wrapped figure going nicely inside the text.}
  \vspace{-10cm}  % as an example, exact margin to be selected
\end{wrapfigure} 
weasel
  • 257