[texhax] Interaction between \iffodd and wrapfig

Hefferon, James S. jhefferon at smcvt.edu
Fri Dec 11 16:17:40 CET 2015


Hello everyone, 

I am trying to put graphics in a document using wrapfig.  I want a graphic to be wrapped on one side of the page on odd pages, and on the other side on even pages, so it would be on the outside in both cases.

To determine if the current page is odd I use the changepage package's \checkoddpage and \ifodd construct, as in the mwe below.

But the mwe document below does this: 

* if wrapfig is commented out then I get just what I expect, a bunch of K's followed by a bunch of O's at the start, where I invoked the macro \margingraphic. That is what I expect.

* if wrapfig is uncommented then the K's appear where I put them, but the O's now appear at the very end of the document, after \lipsum[8] (and on the left).  That is not what I expect.  (I certainly compiled twice.)

I am stumped.  I'd be most grateful for a push in the right direction.

Thanks,
Jim

\documentclass{article}
\usepackage{graphicx, caption}
\usepackage{changepage}
\usepackage{wrapfig}

\makeatletter
% Figures sticking into the margin.
% \margingraphic -- graphic that sticks out into margin
% #1 width of graphic (before it is shifted)
% #2 graphic filename
% #3 caption
\newcommand{\margingraphic}[3][0.2\textwidth]{%
  \mbox{\checkoddpage\ifoddpage% changepage docs recommend the \mbox{..}
    KKKKKK
      \begin{wrapfigure}{R}{0.3\textwidth}
        OOOOO
      \end{wrapfigure}
    \else%
      % \begin{wrapfigure}{L}{0.3\textwidth}
          EEEEEE
      % \end{wrapfigure}
    \fi}%
}
\makeatother

\usepackage{lipsum}
\begin{document}
\margingraphic{ctan_lion.png}{test caption}
\lipsum[1-5]

\lipsum[6-8]
\end{document}



More information about the texhax mailing list