[texhax] Interaction between \iffodd and wrapfig

Donald Arseneau asnd at triumf.ca
Sat Dec 12 03:53:38 CET 2015


On Fri, December 11, 2015 7:17 am, Hefferon, James S. wrote:

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

Ouch! Wrapfig has "i"nside and "o"utside placement options.

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

Check the log file for an error or warning message about
the float-to-end.

> % 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}%
> }

As already answered, wrapfig needs to be in (or before) the paragraph,
not in \mbox.

You have capital placement, meaning floating, which will take it
to the next paragraph after KKKKK. Lowercase r/l/i/o would put it
right at the KKKKK, but you probably want to put wrapfig before the
KKKKKK.  Anyway, you should use O placement for right-on-odd-pages.

\newcommand{\margingraphic}[3][0.2\textwidth]{%
   \begin{wrapfigure}{O}{0.3\textwidth}
       OOOOO
   \end{wrapfigure}
   KKKKKK
}

But the comments indicate you want the figure (partly?) in the
margin, so specify an [overhang] argument as well.  I guess you
want 0.1\textwidth overhang.

Wrapfig takes 0pt as a width parameter to compute the width
from the graphic.  If your graphics are at natural size, then
just use that.  At least use 0pt as the default parameter.

\newcommand{\margingraphic}[3][0pt]{%
  % \par % maybe?
  \begin{wrapfigure}{O}[0.1\textwidth]{#3}
    \ifdim #3>0pt\relax
       \includegraphics[width=#3]{#1}
    \else
       \includegraphics{#1}
    \fi
    \caption{#2}
  \end{wrapfigure}
}



Donald Arseneau, TRIUMF CMMS, asnd at triumf.ca



More information about the texhax mailing list