3

How can I fix this problem? The text of the second paragraph overwrites the figure and doesn't contain line breaks.

\documentclass[parskip=half]{scrbook}
\usepackage[english]{babel}
\usepackage{graphicx,lipsum,wrapfig}

\begin{document}
\begingroup
\setlength{\columnsep}{30pt}%
\begin{wrapfigure}{r}{0.5\textwidth}
  \centering\includegraphics[width=\linewidth]{example-image-a}
  \caption{A very very very very very very very very long long long caption}
\end{wrapfigure}
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo 

foo foo foo foo foo foo foofoo foo foo foo foo foo foofoo foo foo foo foo foo foo
\endgroup
\end{document}
user4811
  • 4,185
  • I want to change the margin (\columnsep) only for this wrapfigure. – user4811 Sep 24 '13 at 00:40
  • From wrapfig manual: If you put a wrapfigure in a parbox or a minipage , or any other type of grouping, the text wrapping should end before the group does. Only way is to add some more text inside the group. –  Sep 24 '13 at 00:45
  • Damn, you are right. What do you mean by "add some text inside the group"? Is there a work-around for this problem? Maybe another possibility to specify columnsep only for one wrapfigure. – user4811 Sep 24 '13 at 00:53
  • Add some more foos ;-). Alternatively, you can fix more width for wrap figure less width for `\includegraphics and such. –  Sep 24 '13 at 01:01
  • Mmmhhh, this is not an option. The height of my wrapfigure is compared to the width big. – user4811 Sep 24 '13 at 01:16
  • In case my answer was helpful, I would kindly ask you to accept it (see How do you accept an answer?). Otherwise, please indicate the problems left open. – cryingshadow Dec 20 '15 at 00:47
  • @cryingshadow This question just popped to the front page. Unfortunately, the OP has not been seen here since before you answered this question, which was two years after it was asked. So it'll probably go unanswered forever … (I'll flag it for moderator attention. Maybe they can stop it from resurfacing.) – Harald Hanche-Olsen Apr 03 '16 at 22:14

1 Answers1

1

As cited in the comment by Harish Kumar, the manual says that the text wrapping should end before the group does. So we need to add another line of text. But we can do this without actually displaying this added text (using, e.g., phantom) like this:

\documentclass[parskip=half]{scrbook}
\usepackage[english]{babel}
\usepackage{graphicx,lipsum,wrapfig}

\begin{document}
\begingroup
\setlength{\columnsep}{30pt}%
\begin{wrapfigure}{r}{0.5\textwidth}
  \centering\includegraphics[width=\linewidth]{example-image-a}
  \caption{A very very very very very very very very long long long caption}
\end{wrapfigure}
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo

foo foo foo foo foo foo foofoo foo foo foo foo foo foofoo foo foo foo foo foo foo

\phantom{foo}
\endgroup
\end{document}

If this adds too much vertical space, another workaround for this would be to add negative vspace (although bad style, great for quick and dirty workarounds).

cryingshadow
  • 2,350