# Problem with wrapfigure and line breaks in the text

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}

• I want to change the margin (\columnsep) only for this wrapfigure. – user4811 Sep 24 '13 at 0: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. – user11232 Sep 24 '13 at 0: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 0:53
• Add some more foos ;-). Alternatively, you can fix more width for wrap figure less width for \includegraphics and such. – user11232 Sep 24 '13 at 1:01
• Mmmhhh, this is not an option. The height of my wrapfigure is compared to the width big. – user4811 Sep 24 '13 at 1:16

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).