# Latex: align equations

created at 05-18-2021 views: 279

To align equations, we use the align environment, and to use align environment, package amsmath should be called.

## align environment-method #1¶

this method uses \{split} and ={}& in a \align environment to align equations

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
\begin{split}
equation1 ={}& ...
\end{split} \\
\begin{split}
equation2 ={}& ...
\end{split}\\
equation3 ={}& ...
\end{align}

\end{document}


Notes for this method:

• No blank lines between \begin{align} and \end{split}
• the last equation isn't wrapped in {split} environment.
• add {}& to equal sign of each equation: ={}&
• line break symbols \\ after each equation or \end{split}
• these tips must be noted, or you will get errors or disordered layout.

#### example¶

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
\begin{split}
g(x) ={}& 2[1-(1+x)exp(-x)]/x^2
\end{split}\\
g'(x) ={}& -2[1-(1+x+x^2/2)exp(-x)]/x^2
\end{align}

\end{document} ## align environment-method #2¶

Different from method #1, replace ={}& with &= , and no need for split environment:

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
g(x) &= 2[1-(1+x)exp(-x)]/x^2\\
g'(x) &= -2[1-(1+x+x^2/2)exp(-x)]/x^2
\end{align}

\end{document} also note:

• No blank lines from \begin{split} to \end{align}
• use \\ to make line breaks
• add & to each equal sign of equations

### Align with or without number¶

Actually, in above examples, we have at least two conditions to be considered:

• align with number, or
• align without number

If you don't want equations to be numbered, you just need add a * symbol to the {align} environment, that is:

\begin{align*}
[content...]
\end{align*}


this works for both of the methods mentioned above. The rest elements between \begin{align*} and \end{align*}are all the same as above numbered alignment.

---

## Alignment of long equations in latex¶

Long equations in latex will arise several problems, so here we treat long equations specially.

### problem of number caused by line breaks¶

For long equations, we have to use \\ to make new lines so that the whole equation can be displayed properly. However, this action also cause our single equation be numbered duplicately: to solve this problem, we use a \nonumber mark at the end of lines and before the line break mark \\, except for the one we want the number be displayed at (often the last line):

\begin{align}
[line1...] \nonumber \\
[line2...] \nonumber \\
[line3...]  % show number at this line
\end{align} now, duplicate numbers disappear.

Next, we will adjust the alignment to make the display of the number more proper.

### alignment without an equal sign¶

Alignment of equations in former sections are based on the equal sign =, different equations can be aligned along the vertical line of "=". However, for long equations, how do we adjust multiple lines of a single equation when there is only one equal sign?

Based on last example, we use two key marks to align a long equation with line breaks:

• &=
• \mathrel{phantom{=}}
• \phantom{}: is used to make space, phantom{=} means make a space of which the width is equal to a = sign.
• \mathrel{}: make relation spacing.

syntax:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
[left] &= [line1...] \nonumber \\
&\mathrel{\phantom{=}} [line2...] \nonumber \\
&\mathrel{\phantom{=}} [line3...]  % show number at this line
\end{align}

\end{document}


now, the example equation has a good appearance: • note the & sign before \mathrel

### multiple equal signs in a signal equation¶

In some cases we need to use equal sign multiple times in a single equation, how do we align the equation then?

Since there are equal sign in each line, so the alignment would be easily base on the equal sign again:

syntax:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
[left] &= [line1...] \nonumber \\
&= [line2...] \nonumber \\
&= [line3...]  % show number at this line
\end{align}

\end{document} (note: the example is a fake equation).

created at:05-18-2021 TwoPunch