1

This is a follow-up to First paragraph indented after section title in margin, but I'm unable to vote, comment, or accept answers there because it's made under a guest account and not linked to this account.

Putting section titles in the outer margin when using the memoir class causes a tiny indent for the first paragraph, even with paragraph indent turned off and skipping lines between paragraphs turned on. Gonzalo Medina's answer (change \setaftersecskip to 1sp) fixes that problem, even without the negative indent trick, but it introduces another problem: the section titles no longer line up consistently with the first paragraph of the section. Sometimes the top of the title aligns with the top of the paragraph, sometimes the bottom lines up with the baseline of the first line of the paragraph, and sometimes it is between two paragraphs. Also, it looks like sometimes the line separating paragraphs is too narrow (not a full line height.)

Gonzalo also changed \marginpar in my example to \marginnotes and added that package to the preamble. That seems to fix the first part of the problem, but the line spacing between section/subsection changes still seems off. Is there another way to fix this?

(I don't have a way to edit questions/answers yet, but if someone could merge this question with the other question, that would be fine.)

\documentclass[12pt,a5]{memoir}
\usepackage{lipsum}

\semiisopage%  a default margin layouts

% fix margin notes

\setmarginnotes{3em}{0.2\textwidth}{2\onelineskip}

%% No numbered sections

\setcounter{secnumdepth}{0}

%% Section Names in margin

\newcommand{\marginhead}[1]{%
  \marginpar{\bfseries\centering #1}}

%% set section, subsection and subsubsection headers
%% all the same, small bold text

\setsecindent{0em}
\setaftersecskip{0em}
\setsecheadstyle{\small\marginhead}

\setsubsecindent{0em}
\setaftersubsecskip{0em}
\setsubsecheadstyle{\small\marginhead}

% etc.

%% Paragraph styles
%%
%% no indent, skip line instead

\abnormalparskip{\baselineskip}
\setlength{\parindent}{0pt}

\checkandfixthelayout

\begin{document}

\section{First Section}
\lipsum[1]
\subsection{First Subsection}
\lipsum[1]
\section{Second Section}
\lipsum[1]

\end{document}
1

In my actual project, which is much longer than the MWE, the alignment issue was even worse, plus some of the section titles were getting put in the wrong margin and cut off by the page edge. But I seem to have found a solution, based on this other question, How to keep heading together with text.

What I did was I used both Gonsalo Medina's solution, including the \marginnote substitution, and \needspace, like this:

\newcommand{\marginhead}[1]{%
  \needspace{4em}\marginnote{\bfseries\centering #1}}

\setsecindent{0em}
\setbeforesecskip{-2em}
\setaftersecskip{1sp}
\setsecheadstyle{\small\marginhead}

Etc., for subsection and subsubsection definitions. I had to test a couple values for \needspace before I found one that put the titles in the margin without mangling one or two.

Side Note: I also discovered that the solution didn't work when using \input for modular documents unless the section title is in the same file as the first paragraph in the section. So, I can have:

\section{Title One}
First paragraph goes here.

\input{./tex/module1.tex}

Or, I suppose, put the \section in module1.tex with the first paragraph, but separating them caused the title to be mangled if it was the first thing on a page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.