# How adjust and align properly different equations

I'm trying to write this in latex:

Using the "align" enviroment I'm able to achieve to write this code:

\begin{align}
&\sum_k y_{ik}= \left\{ \begin{array}{l}
1, \\
m,
\end{array} \right.                  & \begin{array}{l}
i=2,...,n,\\
i=1,
\end{array}\\
&\sum_i q_i y_{ij} \le Q_k,           &k=1,...,m,  \\
\sum_j x_{ijk}=    &\sum_j x_{ijk}= y_{ik},              &i=1,...,n, &&k=1,...,m,\\
&\sum_{i,j \in S} x_{ijk} \le |S| -1, &\text{para todo } S \subseteq \{2,...,n\},&& k=1,...,m,
\end{align}


which looks like this:

It's almost perfect, but the equals of the second column are not perfectly aligned, and I don't understand exactly how the enviroment works: why I had to writte two "&&" in some case and just one in other cases? Why the "para todo" (for all in spanish) is not aligned with the column and starts more in the left? It looks as I wanted, but I don't understand why. If somebody can show me how to write it or refer me to some tutorial of the enviroment, I would be really gratefull. Thank you.

• In an align environment, the first & is a rl align pair. That is the text to the left of & is right aligned and the text following a & is left aligned. The next & is an equation separator and the next & is again a rl align pair. I would suggest you use the alignat environment instead where each & is a rl align pair. Thus, abc & def will make the abc right aligned and the def will be left aligned, whereas abc && def will make the abc right aligned and the def to also be right aligned (since there is no empty text in between the &&). – Peter Grill May 1 at 18:04

You can think of the align environment as a table with alternating r and l columns. Every other & (switching from r to l) aligns the surrounding symbols, the others separate content of different alignment positions.

Your first line complicates things a bit, but the aligned environment works:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
\sum_k y_{ik} &= \begin{cases} 1, \\ m, \end{cases} &
\begin{aligned}
i   \\
i
\end{aligned}   &
\begin{aligned}
&= 2, ..., n,   \\
&= 1,
\end{aligned}   \\
\sum_i q_i y_{ij} &\le Q_k, &
k &= 1, ..., m, \\
\sum_j x_{ijk} = \sum_j x_{ijk} &= y_{ik},  &
i &= 1, ..., n, &
k &= 1, ..., m, \\
\sum_{i, j \in S} x_{ijk} &\le |S| - 1, &
\text{para todo } S &\subseteq \{2, ..., n\},   &
k &= 1, ..., m,
\end{align}

\end{document}


I propose this, based on mathtools (needless to load àmsmath) and some trial and error for adjusting the first line:

\documentclass[12pt, a4paper]{report}
\usepackage{mathtools}

\begin{document}

\begin{align}
\sum_k y_{ik} & =\mathrlap{\begin{cases}
1, & i=2,...,n,\\
m, \hspace{6.09em}& i=1,
\end{cases}} \\
\sum_i q_i y_{ij} &\le Q_k, &k&=1,...,m, \\
\sum_j x_{ijk}=\sum_j x_{ijk}&= y_{ik}, &i & =1,...,n, &&k=1,...,m, \\
\sum_{i,j \in S} x_{ijk} &\le |S| -1, &\text{para todo } S & \subseteq \{2,...,n\},&& k=1,...,m,
\end{align}

\end{document}
`