# marginnote always on right side of the page

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?

• 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

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


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
\if@inlabel\leavevmode\fi
\fi
\@tempa{%
\vbox to\z@{%
\vss
\@mn@margintest
\if@reversemargin\if@tempswa
\@tempswafalse
\else
\@tempswatrue
\fi\fi
\rlap{%
\ifx\@mn@currxpos\relax
\if@mn@verbose
\PackageInfo{marginnote}{%
xpos not known,\MessageBreak
\fi
\else\ifx\@mn@currxpos\@empty
\if@mn@verbose
\PackageInfo{marginnote}{%
xpos not known,\MessageBreak
\fi
\else
\if@mn@verbose
\PackageInfo{marginnote}{%
xpos seems to be \@mn@currxpos,\MessageBreak
\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@{%
\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}


• Nice answer! Instead of patching the \marginpar command, is it possible to define a new command, e.g., \rightmarginpar? I'm using \marginpar to define a side note command, which I would like to be always on the right margin, but I don't want to modify marginpar because it may affect other commands. Thanks a lot! – Khue May 8 '18 at 15:42
• I tried your answer in a memoir document but it does not work :( – Khue May 8 '18 at 21:59
• A recent update of the marginnote package (2018/04/13) has changed the way \@mn@@@marginnote is defined. That method now gives errors reporting that \marginnoterightadjust is undefined. If I'm not beaten to it, when I have a fix to this I'll post it as a new answer below. – rbrignall May 14 '18 at 19:43

Further to my comment a few days ago, if you are using the version of the marginnote package dated 2018/04/13 (or newer, at the time of writing), then you need to redefine \@mn@@@marginnote in a different but entirely analogous way.

For those who want to understand what's going on, the code below (and in the answer above) is the half of the definition from marginnote that handles marginnotes in the right hand margin (note the commented-out line \if@tempswa below is what used to find whether we're using an odd or even page: I left this line in to help anyone who is curious).

So, the code below, inserted in your preamble, should be compatible with marginnote versions since April 2018.

\makeatletter
\long\def\@mn@@@marginnote[#1]#2[#3]{%
\begingroup
\if@inlabel\leavevmode\fi
\fi
\@tempa{%
\vbox to\z@{%
\vss
\@mn@margintest
\if@reversemargin\if@tempswa
\@tempswafalse
\else
\@tempswatrue
\fi\fi
%\if@tempswa
\rlap{%
\if@mn@verbose
\PackageInfo{marginnote}{xpos seems to be \@mn@currxpos}%
\fi
\begingroup
\ifx\@mn@currxpos\relax\else\ifx\@mn@currxpos\@empty\else
\kern-\dimexpr\@mn@currxpos\relax
\fi\fi
\ifx\@mn@currpage\relax
\let\@mn@currpage\@ne
\fi
\if@twoside\ifodd\@mn@currpage\relax
\kern\oddsidemargin
\else
\kern\evensidemargin
\fi
\else
\kern\oddsidemargin
\fi
\kern 1in
\endgroup
\kern\marginnotetextwidth\kern\marginparsep
\vbox to\z@{%
\hsize\marginparwidth
\linewidth\hsize
\kern-\parskip
\marginfont\raggedrightmarginnote\strut\hspace{\z@}%
\ignorespaces#2\endgraf
\vss}%
\vss}%
}%
}%
}%
\endgroup
}
\makeatother

• I'm sorry to be a pain, but can I ask: what would I need to change in this block to make all notes appear on the left margin? As you say, the old solutions no longer work. This works, but obviously puts all the notes on the right side. Thanks in advance. – Telemachus Jan 31 at 13:38
• I've posted a parallel question about the left margin here. If you are up for it, post an adjusted answer there, and I'll gladly accept it. – Telemachus Jan 31 at 16:07