Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
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". –  Philippe Goutet Aug 19 '11 at 6:43
    
Ah, thank you, I haven't probably read that. –  Karel Bílek Aug 19 '11 at 13:27

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer
    
I absolutely don't understand why that works, but it does. Thanks! –  Karel Bílek Aug 19 '11 at 13:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.