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.

My documentclass is book, so I've got an even and odd sides. I like that the equation number are always aligned on the right side - independent of the page (even/odd). I started using marginnotes. I wanted to do the same, that the notes are always on the right side of the page? How do I do that?

share|improve this question
1  
I know, you asked for the standard class book and Gonzalo Medina has already presented a brilliant answer, but with the KOMA-script class scrbookit would be a simple class option: \documentclass[twoside=semi]{scrbook}. I don’t know the class memoir, but I wouldn’t be surprised, when there were a similar option. In general both in KOMA-script and in memoir there are a lot of settings available as simple options or commands, which need massive redefinition in a standard class, cf. Gonzalo’s answer. –  Speravir Aug 31 '12 at 22:08

1 Answer 1

Here's one possible solution patching (with the help of the etoolbox package) the LaTeX kernel command \@addmarginpar:

\documentclass[twoside]{book}
\usepackage[centering,marginparwidth=2.5cm]{geometry}
\usepackage{etoolbox}
\usepackage{lipsum}

\makeatletter
\patchcmd{\@addmarginpar}{\ifodd\c@page}{\ifodd\c@page\@tempcnta\m@ne}{}{}
\makeatother
\reversemarginpar

\begin{document}

\chapter{Test Chapter One}
\section{Test Section}
\lipsum[2]\marginpar{test marginnote one}
\lipsum[2-4]\marginpar{test marginnote two}
\lipsum[2-4]\marginpar{test marginnote three}
\lipsum[4-5]]\marginpar{test marginnote three}
\lipsum[6]

\end{document}

enter image description here

With this layout for marginnotes, it's convenient to activate the centering option for the geometry package; further adjustments might be needed so that marginnotes on even pages can be correctly displayed on a printed document.

The above code provides a solution for the standard LaTeX \marginpar command; if \marginnote (from the marginnote package) is used instead of \marginpar to produce the margin notes, then the internal macro \@mn@@@marginnote will have to be redefined:

\documentclass[twoside]{book}
\usepackage[centering,marginparwidth=2.5cm]{geometry}
\usepackage{marginnote}
\usepackage{lipsum}

\makeatletter
\long\def\@mn@@@marginnote[#1]#2[#3]{%
  \begingroup
    \ifmmode\mn@strut\let\@tempa\mn@vadjust\else
      \if@inlabel\leavevmode\fi
      \ifhmode\mn@strut\let\@tempa\mn@vadjust\else\let\@tempa\mn@vlap\fi
    \fi
    \@tempa{%
      \vbox to\z@{%
        \vss
        \@mn@margintest
        \if@reversemargin\if@tempswa
            \@tempswafalse
          \else
            \@tempswatrue
        \fi\fi
          \rlap{%
            \ifx\@mn@currxpos\relax
              \kern\marginnoterightadjust
              \if@mn@verbose
                \PackageInfo{marginnote}{%
                  xpos not known,\MessageBreak
                  using \string\marginnoterightadjust}%
              \fi
            \else\ifx\@mn@currxpos\@empty
                \kern\marginnoterightadjust
                \if@mn@verbose
                  \PackageInfo{marginnote}{%
                    xpos not known,\MessageBreak
                    using \string\marginnoterightadjust}%
                \fi
              \else
                \if@mn@verbose
                  \PackageInfo{marginnote}{%
                    xpos seems to be \@mn@currxpos,\MessageBreak
                    \string\marginnoterightadjust
                    \space ignored}%
                \fi
                \begingroup
                  \setlength{\@tempdima}{\@mn@currxpos}%
                  \kern-\@tempdima
                  \if@twoside\ifodd\@mn@currpage\relax
                      \kern\oddsidemargin
                    \else
                      \kern\evensidemargin
                    \fi
                  \else
                    \kern\oddsidemargin
                  \fi
                  \kern 1in
                \endgroup
              \fi
            \fi
            \kern\marginnotetextwidth\kern\marginparsep
            \vbox to\z@{\kern\marginnotevadjust\kern #3
              \vbox to\z@{%
                \hsize\marginparwidth
                \linewidth\hsize
                \kern-\parskip
                \marginfont\raggedrightmarginnote\strut\hspace{\z@}%
                \ignorespaces#2\endgraf
                \vss}%
              \vss}%
          }%
      }%
    }%
  \endgroup
}
\makeatother

\begin{document}

\chapter{Test Chapter One}
\section{Test Section}
\lipsum[2]\marginnote{test marginnote one}
\lipsum[2-4]\marginnote{test marginnote two}
\lipsum[2-4]\marginnote{test marginnote three}
\lipsum[4-5]\marginnote{test marginnote three}
\lipsum[6]

\end{document}

enter image description here

share|improve this answer

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.