I am trying to implement the solution provided in Equation tag in twoside-mode outer. It seems the solution provides too much space above the align environment. The following code reproduces the problem, and you can also view the attached picture. Compare the first paragraph to the second paragraph.
\documentclass{article}
\usepackage{amsmath}
\usepackage{needspace}
\begin{document}
\setbox0=\hbox{%
\begin{minipage}{\linewidth}%
\begin{align}
a^2=b^2+c^2, \\ d^2 = e^2 + f^2.
\end{align}
\end{minipage}%
}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa:
\Needspace{\ht0}
\begin{align}
a^2=b^2+c^2, \\ d^2 = e^2 + f^2.
\end{align}
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa:
\begin{align}
a^2=b^2+c^2, \\ d^2 = e^2 + f^2.
\end{align}
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
\end{document}
The manual of the Needspace package does make a note that \Needspace should not be used within paragraphs; this might be causing the issue. I would like the spacing within both paragraphs to be identical. How can I achieve this?
Remark. Initially, I thought the problem was caused by Extra space above boxed multi-line equation, but the solution to add
\setlength\abovedisplayskip{0pt}
within the minipage had no effect. This suggests the issue occurs because of the \Needspace command.


\ht0is not the length you want (I would guess) your\setbox(could have use standard latex\sbox) is measuring aminipagewhich by default is vertically centred so\ht0is half its vertical extent (more or less) – David Carlisle Sep 02 '15 at 12:20