2

I'm using wrapfigure to place images on the outside (o) edge of my document. Mostly it seems to work fine but sometimes an image gets placed on the wrong side.

You can see the problem on page 3. The space for the first image is on the left rather than the right and the image doesn't seem to place correctly.

I think it has to do with a command someone helped me write once that forces the end of a wrapfigure environment:

\documentclass[10pt]{report}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[latin]{babel}
\usepackage{blindtext}
\usepackage{forloop}    
\usepackage[twoside,a4paper,portrait,lmargin=10mm,rmargin=10mm,tmargin=14mm,bmargin=9mm]{geometry}  
\begin{document}
% make a command, wrapfill, that forces the end of a wrapfigure
\makeatletter
\def\wrapfill{\par
  \ifx\parshape\WF@fudgeparshape
    \nobreak
    \ifnum\c@WF@wrappedlines>\@ne
      \advance\c@WF@wrappedlines\m@ne
      \vskip\c@WF@wrappedlines\baselineskip
      \global\c@WF@wrappedlines\z@
    \fi
    \allowbreak
    \WF@finale
  \fi
}
\makeatother
\newcounter{ct}
\forloop{ct}{1}{\value{ct} < 12 }%
{
\begin{wrapfigure}{o}{0pt}
  \includegraphics[width=12cm,height=25mm,keepaspectratio=true]{test.jpg}
\end{wrapfigure}
\blindtext
\blindtext
\wrapfill
}
\end{document}

tex file: https://www.dropbox.com/s/30rg37nv2dkpc56/t1.tex
test.jpg: https://www.dropbox.com/s/w5y7ys7twvpmi9c/test.jpg

I'll post a link to the PDF later. I can only include 2 links due to reputation being < 10.

Any idea how I might track down what's going on or how I could fix it?

  • 1
    Welcome to TeX.SX! I am sorry, but I won't download an archive file. I think most users here won't. You really have to prepare an MWE. In best case, you will find your error doing it. If you want to learn something here, it makes no sense to give a big pile of code for review but you should ask a specific question. For a beginning, you could check if your image is too big. Just set width=0.1\linewidth and see if it does place correctly then. – LaRiFaRi Oct 2 '14 at 7:14
4

one of the related articles had what appears to be the answer.

Wrapfigure apparently creating dummy space on a following page

I needed to add \leavevmode to the end of my wrapfill macro:

\makeatletter
\def\wrapfill{\par
  \ifx\parshape\WF@fudgeparshape
    \nobreak
    \ifnum\c@WF@wrappedlines>\@ne
      \advance\c@WF@wrappedlines\m@ne
      \vskip\c@WF@wrappedlines\baselineskip
      \global\c@WF@wrappedlines\z@
    \fi
    \allowbreak
    \WF@finale
  \fi
\leavevmode
}
\makeatother

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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