Identical vertical spacing between paragraphs of different textsize

Something that happens to me very often is that I change the size of certain formula-like material (something close to but not identical to pseudocode in my case) but get inconsistent vertical inter-paragraph spacing as a result. Here is an example:

\documentclass{memoir}

\begin{document}

{
\parindent0pt

1. Setup: \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

2. Core steps: \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

3. Wrapping up: \\
{\footnotesize
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material}
\par}

4. Final steps: \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

}

\end{document}


(The reason for me using \par at the end of each "paragraph" is given in Gonzalo Medina's answer to this question about line spacing.)

The spacing between blocks 2 and 3 is slightly smaller than that between the other blocks of material. How do I fix this most easily? The obvious alternative, omitting \addtolength{\parskip}{\baselineskip} and using \\ at the end of each block of material, seems to lead to identical vertical spacing.

The spacing is not uniform for exactly the same reason why you need the \par before exiting the \footnotesize section: a paragraph is typeset with only one baseline skip, the one which is in force when the paragraph ends.

If you leave out the \par, a \par is seen at the empty line following the closing brace, when the \footnotesize setting has been undone. With the \par, also the first line is typeset with the \footnotesize baseline skip.

What's a way out? Use \par also to separate the first line from the rest (and \nobreak to avoid a page break):

\documentclass{memoir}

\begin{document}

{
\parindent0pt
\setlength{\parskip}{\baselineskip}

1. Setup:\par\nobreak\vspace{-\parskip}
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

2. Core steps:\par\nobreak\vspace{-\parskip}
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

3. Wrapping up:\par\nobreak\vspace{-\parskip}
{\footnotesize
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material}
\par}

4. Final steps:\par\nobreak\vspace{-\parskip}
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

}

\end{document}


The \vspace{-\parskip} is necessary because of the \parskip setting.

What if there is no "introductory line"? Use a strut outside the group (it's an invisible, zero width object that ensures uniform space. The strut is recomputed when a size changing command is issued, but putting it outside the group (or just before \footnotesize) will ensure it is the one for the normal size:

\documentclass{memoir}

\begin{document}

{
\parindent0pt
\setlength{\parskip}{\baselineskip}

\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

\strut{\footnotesize
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material}
\par}

\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

}

\end{document}


A \strut in the same position may or may not be needed also in the first form; it depends on the visual interaction between the normal size line and the following with small type size.

Notice that I used \setlength rather than \addtolength, so as not to make assumptions about the actual value of \parskip. It may be better to add some flexibility to it:

\setlength{\parskip}{1\baselineskip plus 2pt minus 1pt}


to help TeX form a good page; the spaces between the blocks will be the same: all of them will be stretched or shrunk by the same amount.

However, I'd prefer to insert explicit spaces rather than relying on the automatic \parskip, maybe using some macro or environment.

Without the

\parindent0pt
\setlength{\parskip}{\baselineskip}


you could do

\documentclass{memoir}

\begin{document}

\noindent 1. Setup:\par\nobreak\noindent
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

\bigskip

\noindent 2. Core steps:\par\nobreak\noindent
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

\bigskip

\noindent 3. Wrapping up:\par\nobreak\noindent
\strut{\footnotesize
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material} \\
\textit{some really long technical formula-like material}\par}

\bigskip

\noindent 4. Final steps:\par\nobreak\noindent
\textit{some technical formula-like material} \\
\textit{some technical formula-like material} \\
\textit{some technical formula-like material}

\end{document}


Notice the \bigskip to get the spacing between blocks. I've kept the initial strut for the "small type" block, in order to avoid that the lines are too near to each other. (As above, the strut would also be necessary if there were no "introductory lines".)

• Okay, so the algorithm for picking line spacing picks the ... largest character in the paragraph or the first character in the paragraph perhaps? – Lover of Structure Oct 11 '12 at 5:20
• @user14996 I made some changes; never use \\ as a "spacer". – egreg Oct 11 '12 at 8:32
• Thanks a lot! Still wondering about which characters the line spacing algorithm cares about (all characters on a line? the first one in the line? the first one in the block? the tallest one in a block?). – Lover of Structure Oct 11 '12 at 17:44
• @user14996 The tallest on a line and the deepest on the line above (the depth is the amount a character descends under the baseline). – egreg Oct 11 '12 at 17:59
• @LoverofStructure Well, \nobreak is faster than \nopagebreak and in this situation they do the same thing. – egreg Dec 30 '12 at 11:35