0

For the following, I need to find a cleaner way of having one alignat environment and aligning the first two lines with each other while aligning the last two lines with each other so that the vertical spacing is consistent across all the lines.

enter image description here

\documentclass{article}
\usepackage{mathtools, nccmath}

\begin{document} \begin{fleqn}[0pt] \begin{alignat}{2} & a &&= b\ % & x &&= y \end{alignat}\vspace*{-2\baselineskip} \begin{alignat}{2} & a &&= b\ % & xxx &&= yyy \end{alignat} \end{fleqn} \end{document}

Diaa
  • 9,599

2 Answers2

4

You can remove \belowdisplayskip and \abovedisplayskip, but also take care that the interline spacing in displays is enlarged by \jot.

\documentclass[twocolumn]{article}
\usepackage{mathtools, nccmath}

\begin{document}

\begin{fleqn}[14em] \begin{alignat}{2} & a &&= b\ & x &&= y \end{alignat}\par\nopagebreak \vspace*{\dimeval{-\abovedisplayskip-\belowdisplayskip+\jot}}\noindent \begin{alignat}{2} & a &&= b\ & xxx &&= yyy \end{alignat} \end{fleqn}

\end{document}

enter image description here

Note. I used twocolumn and 14em just in order to move the equations nearer to the numbers and better show the alignment in a smaller picture.

egreg
  • 1,121,712
2

This solution (which is inspired by code from appendix D of The TeXbook) follows each alignat group with a statement that works its way recursively up the vertical list and re-inserts only the \hboxes and \penaltys produced by the alignment while removing vertical space from the bottom and top.

\documentclass{article}
\usepackage{mathtools, nccmath}
\def\unpack{\unskip\unpenalty\unskip % remove space from bottom
  \count0=\lastpenalty\unpenalty
  \setbox0=\lastbox
  \ifhbox0{\unpack}\box0 \penalty\count0 \else
  \unskip\unskip\unpenalty\unskip\unskip\unskip % remove space from top
  \fi}
\begin{document}
\begin{fleqn}[0pt]
\vbox{
\begin{alignat}{2}
  & a &&= b\\
  & x &&= y
\end{alignat}
\par\unpack
\begin{alignat}{2}
  & a &&= b\\
  & xxx &&= yyy
\end{alignat}
\par\unpack
}
\end{fleqn}
\end{document}

output

The \vbox is necessary because \lastbox cannot be used on the main vertical list.