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:

![Chapter heading and precis](https://i.stack.imgur.com/5zLpb.png)

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.

![Correct: aligned first paragraphs](https://i.stack.imgur.com/EsPTm.png)

![Correct: 3-line precis pushes down](https://i.stack.imgur.com/2r8Cu.png)

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?

![Incorrect](https://i.stack.imgur.com/UdxAr.png)

---

### 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.