# typesetting 2 line conditions over which is summed

I am trying to typeset the formula below in a way that m_j=m_i and z_j=z_i have the same scriptsize, the = are aligned, and j: is before both, larger and with vertical position between the lines. How can this be done?

\documentclass[a4paper,12pt]{book}
\usepackage{amsmath,amssymb}

\begin{document}

\begin{align}
y&=\sum_i\frac{\left(1-\frac{1}{\sum_{j:_{m_j=m_i}^{z_j=z_i}}
{f(m(j),z(j),s(j))}}\right)^2}{1}\\
y&=\sum_i\frac{\left(1-\frac{1}{\sum_{j:\substack{m_j=m_i\\z_j=z_i}}
{f(m(j),z(j),s(j))}}\right)^2}{1}\\
y&=\sum_i\frac{\left(1-\frac{1}{\sum_{j:\stackrel{m_j=m_i}{z_j=z_i}}
{f(m(j),z(j),s(j))}}\right)^2}{1}
\end{align}

\end{document}

-

You may also want to consider using the subarray environment provided by the amsmath package.

In the MWE below, the first equation uses this environment to typeset the "inner" formula of your example. The second equation, which places this inner formula into the full expression, looks cramped because, by TeX's rules, the contents of the inner formula are all set in scriptscriptstyle/scriptstyle. At the same time, the parentheses that surround the numerator are over-sized because they use \left and \right directives. Relative to the second equation, the third equation uses (i) the \dfrac command to restore the overall look of the inner formula, (ii) a pair of \bigl( and \bigr) parentheses to help distinguish visually among the plethora of parentheses, (iii) a pair of \Biggl( and \Biggr) directives to surround the numerator, and (iv) the \mathlarger command (which is provided by the relsize package) to increase the size of the outer summation sign.

\documentclass{article}
\usepackage{amsmath,relsize}
\begin{document}
\begin{gather*}
\sum\nolimits_{j:\,
\begin{subarray}{c}
m_j=m_i \\ z_j=z_i
\end{subarray}}
f(m(j),z(j),s(j)) \\
y = \sum_i \frac{\left( 1-\frac{1}{
\sum\nolimits_{j:\,
\begin{subarray}{c}
m_j=m_i \\ z_j=z_i
\end{subarray}}
f(m(j),z(j),s(j))}\right)^2}{i}\\
y = \mathlarger{\sum}_i \frac{\Biggl( 1-\dfrac{1}{
\sum\nolimits_{j: \,
\begin{subarray}{c}
m_j=m_i \\ z_j=z_i
\end{subarray}}
f\bigl(m(j),z(j),s(j)\bigr)}\Biggr)^2}{i}
\end{gather*}
\end{document}


-
I like in @egreg's response that the conditions are smaller than the j, but the larger sum sign is definitively a good idea. –  Markus Schmassmann May 3 '12 at 14:58
To get the conditions typeset smaller than the letter j, just replace the line m_j=m_i \\ z_j=z_i with \scriptscriptstyle m_j=m_i \\ \scriptscriptstyle z_j=z_i (i.e., precede each condition with its own \scriptscriptstyle directive). –  Mico May 3 '12 at 15:29

This is possible also with standard LaTeX methods, but in this case a direct approach with TeX primitives is handier

\documentclass{article}
\usepackage{amsmath}

\newcommand\mycomplicatedsubscript{
j\colon
\vcenter{
\offinterlineskip
\halign{
\hfil$\scriptscriptstyle##$&$\scriptscriptstyle##$\hfil\cr
\mathstrut m_j&=m_i\cr\noalign{\kern1pt}
z_j&=z_i\cr
}}
}

\begin{document}

$y=\sum_i\frac{\biggl(1-\dfrac{1}{\sum_{\mycomplicatedsubscript}f(m(j),z(j),s(j))}\biggr)^2}{1}$
\end{document}


Notice the use of \dfrac and of \biggl and \biggr rather than \left and \right that would unbalance the parentheses, because the denominator is much taller than the numerator.

-
Why m^{}_j instead of just m_j? –  Markus Schmassmann May 3 '12 at 12:33
@MarkusSchmassmann It's a remain of a previous attempt. The \mathstrut in the first line is better for getting the j: in the middle, as it compensates for the subscript j at the bottom. –  egreg May 3 '12 at 12:34
@MarkusSchmassmann Sorry, but I don't think that a larger summation symbol is a good idea. –  egreg May 5 '12 at 12:55