# How to align the baseline of margin notes in LaTeX with the main text?

In an effort to find a workaround for another problem (posted as a question here) I am willing to set up my book (based on the KOMA-script class scrbook) with a symmetrical layout. Like before, I would like to also create margin notes alongside the main text. Here's a MWE to illustrate, what I have so far:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyBook}[2016/10/01 My Book Class]

% General setup
\RequirePackage{blindtext}
\RequirePackage{calc}
\RequirePackage{color}
\definecolor{orange}{rgb}{1.0, 0.5, 0.0}
\newcommand\pagedivisions{14}

% Page Layout
a4paper,
twoside,
titlepage,
fontsize = 9pt,
parskip = full,
index = totoc,
listof = totoc,
bibliography = totoc,
numbers = noenddot,
appendixprefix = true,
captions = nooneline
]{scrbook}

\newlength{\completemargin}
\setlength{\completemargin}{4.125cm}

\RequirePackage{geometry}
\geometry{
reversemarginpar,
inner  = 21cm /  \pagedivisions,
outer  = 21cm / \pagedivisions * 2 + \completemargin,
top    = 29.7cm / \pagedivisions,
bottom = 29.7cm / \pagedivisions,
heightrounded
}

% Use scrlayer-scrpage, so that package notecolumn works
\RequirePackage[
headwidth = 21cm - 21cm / \pagedivisions * 3 : 0cm,
footwidth = 21cm - 21cm / \pagedivisions * 3 : 0cm,
plainfootsepline,
]{scrlayer-scrpage}

% Set up the note column
\RequirePackage{scrlayer-notecolumn}
\newlength{\notescolwidth}
\setlength{\notescolwidth}{\completemargin - \marginparsep}

\DeclareNewNoteColumn[
normalmarginpar,
width = \notescolwidth,
font = \raggedright\footnotesize\color{orange}
]{notes}


And here's a sample file for testing the layout:

\documentclass[english]{MyBook}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{babel}
\begin{document}

\Blindtext[2]

\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}\Blindtext[4]

\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}\Blindtext[3]
\end{document}


Compiled with LyX the layout looks like this:

I guess, you can already see the problem: Is there a way for aligning the baselines of (at least the first line of) the margin notes to the paragraphs they belong to? Please note that this has to be done in the class file (no changes in the main LyX file, please), as that same book will be compiled into different layouts in the future.

Any help will be much appreciated.

You placed your notes between paragraphs where LaTeX was still in vmode. If you want to align the notes with the next paragraph, you should place it IN the next paragraph. You can use things like \leavevmode, \noindent, \null or \strut to place them at the very start of the next paragraph.

\documentclass[a4paper,
twoside,
titlepage,
fontsize = 9pt,
parskip = full,
index = totoc,
listof = totoc,
bibliography = totoc,
numbers = noenddot,
appendixprefix = true,
captions = nooneline]{scrbook}
%\usepackage[T1]{fontenc}
%\usepackage[latin9]{inputenc}
% General setup
\usepackage{blindtext}
\usepackage{calc}
\usepackage{color}
\definecolor{orange}{rgb}{1.0, 0.5, 0.0}
\newcommand\pagedivisions{14}

\newlength{\completemargin}
\setlength{\completemargin}{4.125cm}

\RequirePackage{geometry}
\geometry{
reversemarginpar,
inner  = 21cm /  \pagedivisions,
outer  = 21cm / \pagedivisions * 2 + \completemargin,
top    = 29.7cm / \pagedivisions,
bottom = 29.7cm / \pagedivisions,
heightrounded
}

% Use scrlayer-scrpage, so that package notecolumn works
\usepackage[
headwidth = 21cm - 21cm / \pagedivisions * 3 : 0cm,
footwidth = 21cm - 21cm / \pagedivisions * 3 : 0cm,
plainfootsepline,
]{scrlayer-scrpage}

% Set up the note column
\usepackage{scrlayer-notecolumn}
\newlength{\notescolwidth}
\setlength{\notescolwidth}{\completemargin - \marginparsep}

\DeclareNewNoteColumn[
normalmarginpar,
width = \notescolwidth,
font = \raggedright\footnotesize\color{orange}
]{notes}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
%\usepackage{babel}
\begin{document}

\Blindtext[2]

\leavevmode\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}\Blindtext[4]

\strut\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}\Blindtext[3]
\end{document}


To always add \leavevmode:

\let\oldmakenote=\makenote
\def\makenote{\ifvmode\leavevmode\fi\oldmakenote}

• Oh, I wasn't aware that I was placing the note between the paragraphs... I thought, the beginning of the current paragraph was also part of the paragraph? Anyway: Thanks, that worked well. (Do you think there's a way to include \leavevmode in the class file somehow, so that the people typing the main text do not have to remember the command?) Oct 11, 2016 at 15:47
• If you mean replacing \makenote, that can be done, but I'm not sure if using \leavevmode when not in vmode is a good idea. Oct 11, 2016 at 15:55
• Yeah, something to that effect. The problem is that the class file will also be used by other authors and I would like to hide most of the complications from them. They are using LyX and having to type Strg-L to enter \makenote as a LaTeX command is already asking a lot... :) Oct 11, 2016 at 16:03
• Ah, I noticed you already edited the answer. Thanks a lot, I will try that, but it looks as if it will solve the problem. Oct 11, 2016 at 16:04
• The answer saved me from having some \makenote into a new blank page. Thank you Nov 20, 2016 at 2:07