4

I have encountered a strange behaviour of wrapfigure, that I have isolated in the following example. I don't know if it's a bug or not.

I have this latex source:

\documentclass[a4paper]{article}


\usepackage[czech]{babel}

\usepackage{graphicx}
\usepackage{wrapfig}

\newenvironment{myenvironment}{}{}

\def\poisonousparagraph{

\begin{myenvironment}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at rhoncus libero. Nunc auctor neque ut urna sodales vestibulum. 

\end{myenvironment}

}

\begin{document}


\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \includegraphics[width=0.48\textwidth]{some_picture}
  \end{center}

  \caption{Lorem ipsum}
\end{wrapfigure}



\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph



\end{document}

Instead of the paragraphs with Lorem ipsums wrapping nicely, they are only a half-page wide in the entire document, exactly like this (link to my server with the PDF).

What, however, "fixes" the problem is making the text in poisonousparagraph longer. Or, if I delete the myenvironment altogether. However, in real example, I do need to use custom environments and I do need to use short text like this.

What is going on exactly?

edit: as I have tried, it has nothing to do with the picture itself, if I change it to a .png one, it still does the same thing. Also, it behaves the same when using both latex and pdflatex.

2
  • 2
    This behavior is mentioned in the documentation (which is at the end of the file wrapfig.sty): "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". Aug 19, 2011 at 6:43
  • Ah, thank you, I haven't probably read that. Aug 19, 2011 at 13:27

2 Answers 2

2

Putting at the end of \poisonousparagraph what the content of the internal wrapfig command \WF@mypar does seems to do the trick (I've replaced the image by a rule of about the same size):

enter image description here

\documentclass[a4paper]{article}

\usepackage[czech]{babel}

\usepackage{graphicx}
\usepackage{wrapfig}

\newenvironment{myenvironment}{}{}

\makeatletter
\def\poisonousparagraph{

\begin{myenvironment}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at rhoncus libero. Nunc auctor neque ut urna sodales vestibulum. 

\end{myenvironment}
\@@par
\ifnum\@@parshape=\z@ \let\WF@pspars\@empty \fi % reset `parshape'
\global\advance\c@WF@wrappedlines-\prevgraf \prevgraf\z@
\ifnum\c@WF@wrappedlines<\tw@ \WF@finale \fi

}
\makeatother

\begin{document}

\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \rule{0.48\textwidth}{2cm}
  \end{center}

  \caption{Lorem ipsum}
\end{wrapfigure}

\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph

\end{document}
1
  • I absolutely don't understand why that works, but it does. Thanks! Aug 19, 2011 at 13:41
1

The solution from Philippe Goutet is perfect, but I would like to offer an easier way just FYI.

According to wrapfig documentation

\linewidth is now adjusted within the wrapped text, but since it can only be set for whole paragraphs at a time, it will persist with the wrong value after the wrapping, until the paragraph is finished.

Therefore, you would like to restart the paragraph manually by inserting \ after your wrapfig, here is what you may want to do

\documentclass[a4paper]{article}

\usepackage[czech]{babel}

\usepackage{graphicx}
\usepackage{wrapfig}

\newenvironment{myenvironment}{}{}

\def\poisonousparagraph{

\begin{myenvironment}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at rhoncus libero. Nunc auctor neque ut urna sodales vestibulum. 

\end{myenvironment}

}

\begin{document}

\begin{wrapfigure}{r}{0.5\textwidth}
\begin{center}
\includegraphics[width=0.48\textwidth]{back.jpg}
\end{center}

\caption{Lorem ipsum}
\end{wrapfigure}
\
\

\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph

\end{document}

And here is what it looks like

warp figure

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .