[Tex/LaTex] How to align the baseline of margin notes in LaTeX with the main text

koma-scriptmarginnotescrbookvertical alignment

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{leading}
\RequirePackage{calc}
\RequirePackage{color}
\definecolor{orange}{rgb}{1.0, 0.5, 0.0}
\newcommand\pagedivisions{14}

% Page Layout
\LoadClass[
  a4paper,
  twoside,
  titlepage,
  fontsize = 9pt,
  parskip = full,
  headings = small,
  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,
  plainheadsepline,
  headsepline = 1pt,
  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}

\chapter{Chapter Heading}

\Blindtext[2]

\section{Section Heading}

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

\subsection{Sub Section Heading}

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

enter image description here

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.

Best Answer

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,
  headings = small,
  index = totoc,
  listof = totoc,
  bibliography = totoc,
  numbers = noenddot,
  appendixprefix = true,
  captions = nooneline]{scrbook}
%\usepackage[T1]{fontenc}
%\usepackage[latin9]{inputenc}
% General setup
\usepackage{blindtext}
\usepackage{leading}
\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,
  plainheadsepline,
  headsepline = 1pt,
  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}

\chapter{Chapter Heading}

\Blindtext[2]

\section{Section Heading}

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

\subsection{Sub Section Heading}

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