# Sum alignment in equations

What is the best way to align equal signs and sum symbols in the following MWE?

\documentclass[a4paper]{report}
\usepackage{amsmath}
\begin{document}

\begin{alignedat}{4} y_\text{L} = & \sum_{s=1}^n \left( Y_s \, \lambda_s \right) & \quad & \\ x = & \sum_{s=1}^n \left( X_s \, \lambda_s \right) & \quad & x \geq 0 \\ & \sum_{s=1}^n \lambda_s = 1 & \quad & \lambda_s \geq 0 \end{alignedat}

\end{document}


This is not perfect but works. As far as I know &= should be preferred over =& since the latter causes the space shrieked. But I cannot achieve desired alignment with &=.

• Could you please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Could you also show an example of the output you get now and the output you want? – darthbith Sep 19 '14 at 11:51
• On compiling, it looks OK to me. One might consider another layout if the last line doesn't have the same semantic status as the two above. – Bernard Sep 19 '14 at 12:02
• It compiles, but the horizontal space between = and Σ is smaller than I would like (I'd like it to be as in the ordinary $$y_\mathrm{L} = \sum_{s=1}^n (Y_s \, \lambda_s)$$). – MMSt Sep 19 '14 at 15:56

Please clarify what exactly you want to achieve! Here is your code how I would have written it:

\documentclass[a4paper]{report}
\usepackage{mathtools}
\begin{document}
\begin{alignedat}{2} y_\mathrm{L} &= \sum_{s=1}^n (Y_s \, \lambda_s)\\ x &= \sum_{s=1}^n (X_s \, \lambda_s) &&\qquad x \geq 0\\ &\mathrel{\hphantom{=}} \sum_{s=1}^n \lambda_s = 1 &&\qquad \lambda_s \geq 0\\ \sum_{s=1}^n \lambda_s &= 1 &&\qquad \lambda_s \geq 0 \end{alignedat}
\end{document}


You may decide if you want to have the last or the previous line.

Please note that the use of \left( and \right) is not needed here and does change the spacing. For this very case, \sum_{s=1}^nY_s\lambda_s would be enough to be understood right.

If you like, you may write x_{\phantom{s}}\geq 0 in order to get the inequalities aligned as well.

• It looks very good. I'll go this way. Can you, please, explain how \mathrel{\hphantom{=}} differs from e.g. \phantom{{}={}} or \phantom{{}=}. – MMSt Sep 19 '14 at 15:38

very simple use &= in the first two equation on the third line you add \quad in front of equation as shown below:

\begin{alignedat}{4}

y_\text{L} &= \sum_{s=1}^n \left( Y_s \, \lambda_s \right) & \quad &\\

x       &= \sum_{s=1}^n \left( X_s \, \lambda_s \right) & \quad & x \geq 0\\


• This is the easiest way, indeed. But it is not 'perfectly' aligned. The \quad is a bit (5.2626 % :-)) to small. – LaRiFaRi Sep 19 '14 at 13:12