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 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}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
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
    
Perfect. Thanks for the quick reply. –  GregH Nov 10 '11 at 16:33
add comment

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.