[Tex/LaTex] Mathtools: using substack to align limits

mathtoolssubscripts

I want to align the limits of a sequence at the equal sign but have an optional modifier before the substack. When I add this optional modifier, the limits are distorted since the modifier is placed in the middle. If I remover it, the limits are okay.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
Distortion
\[
\sum_{k:\substack{
  \mathllap{X(S_k)} = \mathrlap{x_i,}\\
  \mathllap{Y(S_k)} = \mathrlap{y_j}}
\]
Okay
\[
\sum_{\substack{
  \mathllap{X(S_k)} = \mathrlap{x_i,}\\
  \mathllap{Y(S_k)} = \mathrlap{y_j}}
\]
\end{document}

Without k

enter image description here

With k

enter image description here

Best Answer

You could just use the aligned environment to do the alignment:

enter image description here

Notes:

  • The difference in the first two is where the k: is located.
  • There must be a better way to enforce \scriptstyle.

Code:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
Ok?
\[
S_1 = \sum_{\mathclap{k:~\substack{\setlength{\jot}{-0.8\baselineskip}\everymath{\scriptstyle}\begin{aligned}
   \scriptstyle X(S_k) &\scriptstyle= x_i,\\
   \scriptstyle Y(S_k) &\scriptstyle= y_j,
  \end{aligned}
  }}}
  x_i + y_i
  \quad\text{or }
S_1 = \sum_{\mathclap{\substack{\setlength{\jot}{-0.8\baselineskip}\everymath{\scriptstyle}\begin{aligned}
   \scriptstyle k:~ X(S_k) &\scriptstyle= x_i,\\
   \scriptstyle Y(S_k) &\scriptstyle= y_j,
  \end{aligned}
  }}}
  x_i + y_i
\]
Okay
\[
S_2 = \sum_{\mathclap{\substack{\setlength{\jot}{-0.8\baselineskip}\begin{aligned}
    \scriptstyle X(S_k) &\scriptstyle= x_i,\\
    \scriptstyle  Y(S_k) &\scriptstyle= y_j,
  \end{aligned}
  }}}
  x_i + y_i
\]
\end{document}