# [Tex/LaTex] Sum alignment in equations

alignmath-mode

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 &=.

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.