# multlined breaks \substack?

I have some long equations to deal with that don't fit into one line, and love the multlined-environment from mathtools to fit them into (e.g.) an align-environment, particularly if I want to package 2-3 manipulations of the quantity requiring two lines into one block (in the MWE there's only one for brevity).

However, multlined breaks down when there's a \substack inside, see MWE below. It seems that the environment somehow tries to "multline" the \substack, but I haven't managed to prevent multline from "seeing" the \substack to avoid this.

MWE (using knowledge from https://tex.stackexchange.com/a/180549/42225 and the documentation):

\documentclass[12pt,fleqn]{article}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}
\noindent A long equation using \texttt{multline} and \texttt{$\backslash$substack},
%
\begin{multline*}
\mathcal{X}=\sum_{\substack{i,j,k,\ell,m,n,p,q,r,s,t\\ i+j\equiv 1 \bmod{2}}}  \binom{...}{i} \binom{...}{j} \binom{...}{k} \binom{...}{\ell} \binom{...}{m} \binom{...}{n} \cdot\ldots\\
\ldots \cdot \binom{...}{p} \binom{...}{q} \binom{...}{r} \binom{...}{s} \binom{...}{t},
\end{multline*}
%
breaks when using \texttt{multlined} instead of \texttt{multline},
%
\begin{align*}
\MoveEqLeft[2]% default is 2em
\mathcal{X}\\
&\!\begin{multlined}[t][\linewidth-\mathindent-2em-\multlinegap]
=\sum_{\substack{i,j,k,\ell,m,n,p,q,r,s,t\\ i+j\equiv 1 \bmod{2}}}  \binom{...}{i} \binom{...}{j} \binom{...}{k} \binom{...}{\ell} \binom{...}{m} \binom{...}{n} \cdot\ldots\\
\ldots \cdot \binom{...}{p} \binom{...}{q} \binom{...}{r} \binom{...}{s} \binom{...}{t},
\end{multlined}\\
&=1,
\end{align*}
%
but still works fine without \texttt{$\backslash$substack},
%
\begin{align*}
\MoveEqLeft[2]% default is 2em
\mathcal{X}\\
&\!\begin{multlined}[t][\linewidth-\mathindent-2em-\multlinegap]
=\sum_{i,j,k,\ell,m,n,p,q,r,s,t}  \binom{...}{i} \binom{...}{j} \binom{...}{k} \binom{...}{\ell} \binom{...}{m} \binom{...}{n} \cdot\ldots\\
\ldots \cdot \binom{...}{p} \binom{...}{q} \binom{...}{r} \binom{...}{s} \binom{...}{t}.
\end{multlined}\\
&=1,
\end{align*}

\end{document}

• Nasty bug indeed. – egreg Oct 3 '15 at 13:15
• clearly a bug ... somewhere ... i am trying to test it in some other contexts to determine whether the problem is with amsmath or mathtools; in either case, i'm adding it to the amsmath bugs list, as this is a reasonable construction that should be able to work without problems. – barbara beeton Oct 3 '15 at 14:51
• @egreg @barbarabeeton Note that the problem only happens in the first line. So it has to do with the first line trickery that multlined does behind the scenes. – daleif Oct 5 '15 at 9:14

With help of stackengine you can obtain:

In code below I borrow solution provided by author of stacengine in his answer in A new line inside subscript:

\documentclass[12pt,fleqn]{article}
\usepackage{mathtools}
\usepackage{stackengine}

\begin{document}
\noindent A long equation using \texttt{multline} and \texttt{$\backslash$substack},
%
\begin{multline*}
\mathcal{X}=\sum_{\substack{i,j,k,\ell,m,n,p,q,r,s,t\\ i+j\equiv 1 \bmod{2}}}  \binom{...}{i} \binom{...}{j} \binom{...}{k} \binom{...}{\ell} \binom{...}{m} \binom{...}{n} \cdot\ldots\\
\binom{...}{p} \binom{...}{q} \binom{...}{r} \binom{...}{s} \binom{...}{t},
\end{multline*}
%
breaks when using \texttt{multlined} instead of \texttt{multline},
%
\begin{align*}\def\useanchorwidth{T}\stackMath
%\MoveEqLeft[2]% default is 2em
\mathcal{X}
&\begin{multlined}[t][\linewidth-\mathindent-2em-\multlinegap]
=\mathop{\stackunder{\sum}{\def\stackalignment{c}%
\stackunder[2pt]{\scriptscriptstyle i,j,k,\ell,m,n,p,q,r,s,t}
{\scriptscriptstyle i+j\equiv 1 \bmod{2}}
}}
\binom{...}{i} \binom{...}{j} \binom{...}{k} \binom{...}{\ell} \binom{...}{m} \binom{...}{n} \cdot\ldots\\
\ldots \cdot \binom{...}{p} \binom{...}{q} \binom{...}{r} \binom{...}{s} \binom{...}{t},
\end{multlined}\\
&=1,
\end{align*}
%
but works fine without \texttt{$\backslash$substack},
%
\begin{align*}
\MoveEqLeft[2]% default is 2em
\mathcal{X}\\
&\!\begin{multlined}[t][\linewidth-\mathindent-2em-\multlinegap]
=\sum_{i,j,k,\ell,m,n,p,q,r,s,t}  \binom{...}{i} \binom{...}{j} \binom{...}{k} \binom{...}{\ell} \binom{...}{m} \binom{...}{n} \cdot\ldots\\
\ldots \cdot \binom{...}{p} \binom{...}{q} \binom{...}{r} \binom{...}{s} \binom{...}{t}.
\end{multlined}\\
&=1,
\end{align*}
\end{document}


It seems that align, substack and multiline doeasn't low each other very much :-(, i.e. here is present a bug.

• Thanks for the suggestion! The spacing in your solution is off, but all that can be fixed (\displaystyle for the \sum, \scriptstyle instead of \scriptscriptstyle, reintroduce \! before multlined, and replace 2em with \widthof{$\mathcal{X}$} if commenting out \MoveEqLeft). I'll see if someone can find a fix for the original environments (so that I don't have to introduce another package), but if not, then I'll accept your answer. Thanks again! – Axel Oct 3 '15 at 13:44
• Since nothing new regarding the bug to be forthcoming at the moment, I'm accepting your answer. Thanks again! – Axel Oct 21 '15 at 8:29