I'm making a custom document class based on memoir, and I don't know how to implement the chapter precis so that it does what I want (the chapter precis is a small optional paragraph that follows chapter headings).
I'd like the actual first paragraph of the chapter to start at a fixed vertical position below the chapter heading, unless the precis is very long, in which case it should push the first paragraph down. Here's what it currently looks like:
I have \setlength{\afterchapskip}{4\baselineskip}
(distance from chapter heading to 1st paragraph), and \setlength{\prechapterprecisshift}{-3\baselineskip}
(taken out of \afterchapskip
if there is a precis). If I don't find a solution, I'll arrange for the spacing after the precis to be 2\baselineskip
so one-line precis won't move the 1st paragraph. However, I'd like two-lines precis to still not push the 1st paragraph down.
Given the way memoir defines \chapterprecis
and offers \prechapterprecis
and \postchapterprecis
hooks, I'm not sure how I can measure the height of the precis. I've also thought making about some sort of paragraph-level strut, but I don't know how (inserting a normal zero-width rule at the beginning of the precis text changes the height of its first line, not of the precis as a whole).
Edit — my current solution
I've slightly adapted @Gonzalo's approach to simplify the height comparison. The minibox
also needed its [t]
argument:
\newlength{\postchapterprecisskip}
\setlength{\prechapterprecisshift}{3\baselineskip}
\setlength{\postchapterprecisskip}{\baselineskip}
\renewcommand\prechapterprecis{\vspace*{-\prechapterprecisshift}}
\renewcommand\postchapterprecis{\vspace*{\postchapterprecisskip}}
\newsavebox\sba@precisbox
\newlength\sba@precisboxht
\newlength\sba@precisboxdp
\renewcommand\chapterprecishere[1]{%
\begin{lrbox}{\sba@precisbox}%
\begin{minipage}[t]{\linewidth}%
\prechapterprecis
\flushright
\begin{balanced}{\linewidth}%
\precisfont\strut##1\strut%
\end{balanced}%
\postchapterprecis
\end{minipage}%
\end{lrbox}%
\settoheight\sba@precisboxht{\usebox\sba@precisbox}%
\settoheight\sba@precisboxdp{\usebox\sba@precisbox}%
\addtolength\sba@precisboxht{\sba@precisboxdp}%
\usebox{\sba@precisbox}\par\unskip%
\ifnum\sba@precisboxht<0pt
\vspace*{-\sba@precisboxht}
\fi}
For chapters with a precis it works nicely, with a consistent vertical position of the first chapter that gets pushed down as soon as the precis takes more than 2 lines.
However, there is a slight shift compared to the first paragraph without a precis (slightly lower. That shift is influenced by adding \hrule
so I'm guessing it's an issue with \par
or \parskip
… any idea?
Edit — Accepted solution
I haven't had much time to adopt one particular solution in my code; I've accepted David's answer because it uses an original technique, but Gonzalo's is probably a bit more general, with some tweaking of the surrounding whitespace.
memoir
handles it, though, so it might not be an easy option.)\prechapterprecis #1\postchapterprecis
, so it's tricky; in the end, I think I will have to forget about those hooks and redefine the whole macro, but I wonder if there is a nicer solution.