5

Somewhat related to aligned in multlined produces superfluous space , there is superfluous space inside multline*, gather*, or align* if its contents contains aligned with at least two columns. Namely, feeding pdflatex with

\documentclass{article}
\pagestyle{empty} 
\usepackage{mathtools}
\begin{document}
\begin{multline*}
  (
    \begin{aligned}[c]
      &\text{an arbitrarily complex formula}
    \end{aligned}
  )
\end{multline*}
\end{document}

yields space between the contents of the aligned environment and the closing right paren:

output

An underfull \hbox is reported to the console.

Who is the culprit and what to do? In other words, where does this space come from and how to get rid of it in a different way than adding some hard-coded negative space (such as \mskip-19mu) manually? Of course, you may say

\documentclass{article}
\pagestyle{empty} 
\usepackage{mathtools}
\begin{document}
\begin{multline*}
  (
    \begin{alignedat}[c]{1}
      &\text{an arbitrarily complex formula}
    \end{alignedat}
    )
  \end{multline*}
\end{document}

and get rid of the space:

output

Still, an underfull \hbox as well as the problem with the original align remain.

1 Answers1

3

The space is always generated by aligned and it's immaterial where it's embedded in. Your example can be reduced to

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$(\begin{aligned} a&=b \end{aligned})$

\end{document}

enter image description here

The extra space usually goes unnoticed, but not when aligned is used like that. The effect is expected, when one looks at how aligned is defined, in particular where the preamble for the internal \halign is generated:

        \ialign\bgroup
           &\column@plus
            \hfil
            \strut@
            $\m@th\displaystyle{##}$%
            \tabskip\z@skip
           &\column@plus
            $\m@th\displaystyle{{}##}$%
            \hfil
            \tabskip\alignsep@
            \crcr

where one clearly sees the \tabskip\alignsep@ at the end. Basically, aligned generates pairs of columns, typeset in display style;

  • first column aligned right,
  • no intervening horizontal space because of \tabskip\z@skip,
  • second column aligned left, with an empty atom at the beginning,
  • horizontal space of width \alignsep@.

The last space is the price to pay for being able to typeset an arbitrary number of pairs of columns.

If you want precise control of the space, use alignedat.

The value of \alignsep@ is usually set to \minalignsep and we can see it at work:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$(\begin{alignedat}{1} a&=b \end{alignedat})$

$(\begin{aligned} a&=b \end{aligned})$

$(\displaystyle a=b\hspace{\minalignsep})$

\end{document}

enter image description here

egreg
  • 1,121,712
  • not sure this is the whole story though,$(\begin{aligned} a&=b \\\end{aligned})$ has no space (and no extra row) well, it unskips, but shouldn't end{aligned} ? – David Carlisle Oct 14 '22 at 20:32
  • @DavidCarlisle No, it's not the full story. With more than two columns the space appears and disappears in “random” situations. – egreg Oct 14 '22 at 20:48
  • First, thanks a lot! Second, it's a bit unsatisfactory for the space to be, erm, random, and, what's worse, undocumented. I could post a bug report against mathtools, if wished… Yes, alignedat solves the issue for me the typesetter. –  Oct 14 '22 at 22:09