# How to align multiline equations?

I am working with equations that are should be broken to multiple lines. The code I wrote is as follows:

\begin{equation}
\begin{aligned}
O_{max} = w_1 \Sigma_{a=1}^{m} \Sigma_{b=a+1}^{n} (-\left|CPT_a
- CPT_b\right|)\\
& + w_2 \Sigma_{j=1}^{m} (DIF_j) + w_3 \Sigma_{j=1}^{m}
(INT_j/\Sigma_{x=1}^{n} x_{ij})
\end{aligned}
\label{equ:ho}
\end{equation}


and the other one is

 \begin{align}
\begin{split}
nr(G_i,r) =
\begin{cases}
1 &  \text{r is naturally played by one member of $G_i$}\\
-2 &  \text{r is not naturally played in $G_i$} \\
-p & \text{r is naturally played by p members in $G_i$}\\
\end{cases}
\end{split} \nonumber \\
\begin{split}
nb(G_i) = \Sigma_{r=1}^{9} nr(G_i,r)\\
& max_{\forall G\in C} \left( b(G) =
\frac{\Sigma_{i=1}^{g}nb(G_i)}{g}\right)
\end{split}
\label{equ:yannibelli}
\end{align}


Alignment of each equation is not the same (second part goes to the right and out of the margin of the pages). How can I fix them, please??

• Should be i=1 in the last sum? – Sigur Dec 31 '19 at 21:11
• Welcome to TSE. I suggest that you post a minimal working example, instead of code snippets. – José Carlos Santos Dec 31 '19 at 21:21

EDIT: 2020/01/01 for the comment of the user @Mico. The first alignment with the important suggestion of the user @Sigur is: \documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{equation}
\begin{aligned}
O_{\max}& = w_1 \sum_{a=1}^{m} \sum_{b=a+1}^{n} (-\lvert\text{CPT}_a
-\text{CPT}_b\rvert)\\
&\quad + w_2 \sum_{j=1}^{m} (\text{DIF}_j) + w_3 \sum_{j=1}^{m}
(\text{INT}_j/\sum_{x=1}^{n} x_{ij})
\end{aligned}
\label{equ:ho}
\end{equation}
\end{document}


For the second code my proposal to align is: \documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{aligned} \mathrm{nr}(G_i,r) & = \begin{cases} 1 & \text{r is naturally played by one member of G_i}\\ -2 & \text{r is not naturally played in G_i} \\ -p & \text{r is naturally played by p members in G_i}\\ \end{cases}\\[3pt] \mathrm{nb}(G_i) & = \sum_{r=1}^{9} \mathrm{nr}(G_i,r)\\ & = \max_{\forall G\in C} \left( b(G) = \frac{\sum\limits_{r=1}^{9}\mathrm{nb}(G_i)}{g}\right) \label{equ:yannibel} \end{aligned}
\end{document}

• I'd use &{}\quad + in the second line. – Sigur Dec 31 '19 at 21:02
• @Sebastiano - In the first row of the first formula, please replace \left| and \right| with \lvert and \rvert. Implementing this change makes a big difference for the spacing between the leading - (minus) symbol and the first vertical bar: With -\lvert, but not with -\left|, one gets the spacing appropriate for a unary operator. – Mico Jan 1 '20 at 3:02
• Thanks a lot. It works. – نسيبة مقطر Jan 1 '20 at 5:53
• @Mico I give you my best wishes of happy 2020!!! Many thanks. – Sebastiano Jan 1 '20 at 12:43
• @Mico, well observed. Done. – Sigur Jan 2 '20 at 12:59

Alignments require the use of alignment symbols - & - to properly indicate the horizontal position within successive lines that will be used for alignment purposes. You don't have any of them in the first construction. Here's how it should look: \begin{equation}
\begin{aligned}
O_{\max} &= w_1 \sum_{a = 1}^m \sum_{b = a + 1}^n (-\lvert CPT_a
- CPT_b \rvert) \\
&\phantom{{}={}} + w_2 \sum_{j = 1}^m (DIF_j) + w_3 \sum_{j = 1}^m
(INT_j / \sum_{x = 1}^n x_{ij})
\end{aligned}
\end{equation}


Note the use of \max and \sum instead of max and \Sigma. You may also consider defining \CPT and \DIF as math operators.

Then, for the second construction, there seems to be no need for split here. You can use a nested equation-aligned just like in the first: \begin{equation}
\begin{aligned}
nr(G_i, r) &=
\begin{cases}
1 & \text{$r$ is naturally played by one member of $G_i$}\\
-2 & \text{$r$ is not naturally played in $G_i$} \\
-p & \text{$r$ is naturally played by $p$ members in $G_i$}\\
\end{cases} \\
nb(G_i) &= \sum_{r = 1}^9 nr(G_i, r) \\
& \max_{\forall G \in C} \left( b(G) = \frac{\sum_{i = 1}^g nb(G_i)}{g} \right)
\end{aligned}
\end{equation}


It really depends on how you want the alignment to occur, together with the numbering. My assumption here is based on a single numbering for each construction.

• Please do not get mad at me but the output makes only limited sense. At least use $r$ is naturally played by $p$ members in $G_i$, i.e. wrap p in \$ signs, and do something with the \max_{\forall G \in C} (add an equality before or whatever, and drop the \forall). I personally would also add punctuations and so on. – user194703 Dec 31 '19 at 21:52
• @Schrödinger'scat: Ahhh, forgot about the p. I'm not sure what the intent of the \max equation is in the OP's request, so I'll leave that as-is. – Werner Dec 31 '19 at 21:56

I'd do like this (using \sum instead of \Sigma): \documentclass{article}
\usepackage{amsmath,amssymb}

\begin{document}
\begin{equation}
\begin{aligned}
O_{\max} &= w_1 \sum_{a=1}^{m} \sum_{b=a+1}^{n} (-|CPT_a - CPT_b|) \\
&\quad + w_2 \sum_{j=1}^{m} DIF_j + w_3 \sum_{j=1}^{m}  \Bigl(INT_j/\sum_{i=1}^{n} x_{ij}\Bigr)
\end{aligned}
\label{equ:ho}
\end{equation}

or another version with \verb|\mathrm{}|:

\begin{equation}
\begin{aligned}
O_{\max} &= w_1 \sum_{a=1}^{m} \sum_{b=a+1}^{n} (-|\mathrm{CPT}_a - \mathrm{CPT}_b|) \\
&\quad + w_2 \sum_{j=1}^{m} \mathrm{DIF}_j + w_3 \sum_{j=1}^{m}  \Bigl(\mathrm{INT}_j/\sum_{i=1}^{n} x_{ij}\Bigr)
\end{aligned}
\label{equ:ho}
\end{equation}
\end{document}

• Here, I have used \sum before but the output present a dot not the summation symbol. That is what direct me to use \sigma! If you know what is the problem, please let me know.. Thanks again. – نسيبة مقطر Jan 1 '20 at 5:55