# Adjust the vertical position of margin notes to the baseline of the body text

I want the first line of my margin notes—which are set in \small size—to be at the height of the baseline of the body text, like this:

My problem is that using something simple like

\documentclass{article}
\usepackage{marginnote}
\renewcommand{\marginfont}{\small}
\begin{document}
What can I do to align the first line of the marginnote?\marginnote{D-D-D-Drop the baseline!}
\end{document}


results in

• @TonioElGringo's answer works as good as @Steven B. Segletes's, with the difference Steven's \mynote is justified. Thank you both, and @karlkoeller too, of course. You're great! :-) Jan 23, 2015 at 14:02

You can write your own with the tabto package. EDITED to flip \mynote margin on every page. You can choose to fix the \mynote in a single margin (left or right) by eliminating the \AddEverypageHook and setting \pagesense to R or L as desired.

\documentclass{article}
\usepackage{marginnote}
\usepackage{lipsum}
\usepackage{tabto,everypage}
\def\pagesense{R}
\renewcommand{\marginfont}{\small}
\newcommand\mynote[1]{%
\if R\pagesense%
\tabto*{\dimexpr\textwidth+\marginparsep\relax}%
\else%
\tabto*{\dimexpr-\marginparsep-\marginparwidth\relax}%
\fi%
\smash{\parbox[t]{\marginparwidth}{\small#1}}%
\tabto*{\TabPrevPos}%
{}%
}
\textwidth=3.9in
\begin{document}
Original marginnote\par
What can I do to align the first line of the marginnote?\marginnote{D-D-D-Drop the baseline!} Here I continue the text.
\vspace{.2in}

Revised mynote\par
What can I do to align the first line of the marginnote?\mynote{D-D-D-Drop the baseline!} Here I continue the text.

\lipsum[1-5]

Another test.\mynote{I should be to the left}

\lipsum[6-10]

Last test.\mynote{I'm back on the right}
\end{document}


• @ArchStanton Thanks. And the nice thing with \mynote is that you can tailor the definition to your need, for example, replacing \small with \small\sffamily\raggedright, etc. Jan 23, 2015 at 11:26
• There's another problem: the notes now are always set in the right margin, instead of the outer margin. Can you correct this? I don't understand your code enough to tweak it with any consciousness of what I'm doing... Jan 23, 2015 at 11:41
• @ArchStanton The line \tabto*{\dimexpr\textwidth+\marginparsep\relax} says to always move to the x-location (relative to the left margin) of \textwidth plus \marginparsep. What you need is to make this tabto* dependent on the page number. I'll see what I can do. Jan 23, 2015 at 11:48
• @ArchStanton Please see revision. Jan 23, 2015 at 11:58

You can use \marginnotevadjust to adjust this.

\renewcommand{\marginnotevadjust}{0.157ex}


It seems to me that the value of 0.157ex is correct but my eyes are not so good, so modify the value if you notice that it's wrong.

MWE

\documentclass{article}
\usepackage{marginnote}
\renewcommand{\marginfont}{\small}
\begin{document}
What the \ldots\ldots\ldots\ldots\ldots can I do to align the first line of the marginnote?\marginnote{D-D-D-Drop the baseline!}
\end{document}


If you need it only for one instance, instead of redefining \marginnotevadjust globally, you can use the optional argument of \marginnote as in

\marginnote{D-D-D-Drop the baseline!}[0.157ex]

• Thank you Karl. I thought there was a more precise way than adjusting the height by eye, though. Jan 23, 2015 at 11:03
• @ArchStanton You're welcome. I thought the right one was 1pt (the difference between \baselineskip with \normalfont and \small) but I was wrong... Jan 23, 2015 at 12:19
• I too have tried with 1 point and 10.00002-9.24994 pt (the difference between normal and small size according to the Wikibook), but that was wrong too. Jan 23, 2015 at 12:29

Here is a quick and dirty hack to get the expected result: just replace the \marginfont definition with this one:

\renewcommand{\marginfont}{\noindent\rule{0pt}{0.7\baselineskip}\tiny}


It will ensure the first line of the margin note has the same height as the one in the text, thus will be aligned.

• Can you tell me how this works? It doesn't seem to be "by eye", but it's weirdly simple :-) Jan 23, 2015 at 13:16
• @ArchStanton \rule{0pt}{0.7\baselineskip} is like strut, so the line has the same height as the text, but with a depth of 0pt instead of 0.3\baselineskip (so it doesn't mess with the next line). Jan 23, 2015 at 13:18
• So basically by default we have \rule[0.3\baselineskip]{0pt}{0.7\baselineskip} and you're removing the 0.3\baselineskip depth to lay the text on the baseline? Jan 23, 2015 at 13:27
• No, basically 0.7\baselineskip is the height of a line in the text, and this code is juste adding an invisible character with that height to the first line of the note, so the line has the same height as the text. This works because the top of the note is aligned with the top of the text line. Jan 23, 2015 at 13:30