6

I would like to put figures in the outer margins of a book. I am using wrapfig to do so, but the figures are aligned differently on even and odd numbered pages. On odd pages, they align based on the edge of the page; on even pages, they align next to the text itself.

Ideally, I would like the figures to be centered in the middle of the margin regardless of even/odd page numbers. How can I accomplish this?

Here is a minimal example.

    \documentclass[10pt]{book}
    \usepackage[paperheight=11in,paperwidth=8.5in, inner=1in,includeheadfoot,textheight=9in,textwidth=345pt,marginparwidth=150pt]{geometry}

    \usepackage{lipsum}
    \usepackage{wrapfig}
    \usepackage{tikz}

    \setlength{\wrapoverhang}{\marginparwidth}
    \addtolength{\wrapoverhang}{\marginparsep}

    \begin{document}
    \begin{wrapfigure}{o}{0pt} 
    \begin{tikzpicture}
    \draw (0,0)--(3,0)--(3,3)--(0,3)--cycle;
    \end{tikzpicture}
    \caption{}\end{wrapfigure}
    \lipsum[1] 

    \begin{wrapfigure}{o}{0pt} 
    \begin{tikzpicture}
    \draw (0,0)--(5,0)--(5,5)--(0,5)--cycle;
    \end{tikzpicture}
    \caption{}\end{wrapfigure}
    \lipsum[1]

    \clearpage

    \begin{wrapfigure}{o}{0pt} 
    \begin{tikzpicture}
    \draw (0,0)--(3,0)--(3,3)--(0,3)--cycle;
    \end{tikzpicture}
    \caption{}\end{wrapfigure}
    \lipsum[1] 

    \begin{wrapfigure}{o}{0pt} 
    \begin{tikzpicture}
    \draw (0,0)--(5,0)--(5,5)--(0,5)--cycle;
    \end{tikzpicture}
    \caption{}\end{wrapfigure}
    \lipsum[1]

    \end{document}
lockstep
  • 250,273
GregH
  • 3,499

1 Answers1

6

One solution would be wrap the figure in a minipage, and use \centering to center the image within the minipage:

\begin{wrapfigure}{o}{0pt}%
\begin{minipage}{\marginparwidth}%
\centering%
    \begin{tikzpicture}
       ...
    \end{tikzpicture}
\caption{}
\end{minipage}
\end{wrapfigure}

enter image description here

To simplify this process it is helpful to define a custom environment, but this is not quite straightforward with wrapfigure. Below, I have adapted the solution provided at Defining a custom ‘wrapfig’ environment to define MyWrapFigure:

\documentclass[10pt]{book}
\usepackage[paperheight=11in,paperwidth=8.5in, inner=1in,includeheadfoot,textheight=9in,textwidth=345pt,marginparwidth=150pt]{geometry}

\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{tikz}

\newenvironment{MyWrapFigure}{%
    \wrapfigure{o}{0pt}%
    \begin{minipage}{\marginparwidth}%
    \centering%
}{%
    \end{minipage}%
    \endwrapfigure%
}

\setlength{\wrapoverhang}{\marginparwidth}
\addtolength{\wrapoverhang}{\marginparsep}

\begin{document}
\begin{MyWrapFigure}
\begin{tikzpicture}
\draw (0,0)--(3,0)--(3,3)--(0,3)--cycle;
\end{tikzpicture}
\caption{}
\end{MyWrapFigure}
\lipsum[1] 

\begin{MyWrapFigure}
\begin{tikzpicture}
\draw (0,0)--(5,0)--(5,5)--(0,5)--cycle;
\end{tikzpicture}
\caption{}
\end{MyWrapFigure}
\lipsum[1]

\clearpage

\begin{MyWrapFigure}
\begin{tikzpicture}
\draw (0,0)--(3,0)--(3,3)--(0,3)--cycle;
\end{tikzpicture}
\caption{}
\end{MyWrapFigure}
\lipsum[1] 

\begin{MyWrapFigure}
\begin{tikzpicture}
\draw (0,0)--(5,0)--(5,5)--(0,5)--cycle;
\end{tikzpicture}
\caption{}
\end{MyWrapFigure}
\lipsum[1]
\end{document}
Peter Grill
  • 223,288
  • Nice solution; rather than using 150pt as the width for the minipage, you could use \marginparwidth which would change if the page dimensions change – cmhughes Nov 10 '11 at 15:44
  • @cmhughes: Excellent suggestion. Have incorporated that into the updated solution. – Peter Grill Nov 10 '11 at 15:55