LatexNotes

Lesson 10 of 12

Equations over several lines

Line a calculation up at its equals signs, number equations, and label them. About ten minutes.

A worked solution runs over several lines, and reads best when every equals sign sits under the one above. align* does exactly that, with the same & and \\ you used for matrices.

Lining up at the equals sign

Put the lines between \begin{align*} and \end{align*}. Put & just before each equals sign, and \\ at the end of every line but the last:

2x+3=72x=4x=2\begin{align*} 2x + 3 &= 7 \\ 2x &= 4 \\ x &= 2 \end{align*}

The & marks the point that lines up, so it can go before any sign: &\leq, &\approx, &\Rightarrow.

Carrying on a calculation

When a line carries on from the one above, leave the left side empty and start with &=:

(a+b)2=(a+b)(a+b)=a2+ab+ba+b2=a2+2ab+b2\begin{align*} (a+b)^2 &= (a+b)(a+b) \\ &= a^2 + ab + ba + b^2 \\ &= a^2 + 2ab + b^2 \end{align*}

Numbered equations

Without the star, align numbers every line, so you can refer to them later:

E=mc2F=ma\begin{align} E &= mc^2 \\ F &= ma \end{align}

For one numbered equation there is equation. To give a line your own label, put \tag{...} at its end: E = mc^2 \tag{1}. In a full document, \label{...} on a line and \ref{...} in your text make LaTeX write the number for you:

LaTeX
\begin{equation}
  E = mc^2 \label{eq:energy}
\end{equation}
By \eqref{eq:energy}, ...

These environments come from the amsmath package, so a document that uses them needs \usepackage{amsmath} at the top. You will see a whole document in lesson 12.

Centred lines

gather* puts each line in the centre, without lining anything up. It suits a list of separate results:

x+y=5x−y=1\begin{gather*} x + y = 5 \\ x - y = 1 \end{gather*}

Practise

  1. 2x+3=72x=4x=2\begin{align*} 2x + 3 &= 7 \\ 2x &= 4 \\ x &= 2 \end{align*}

  2. (a+b)2=(a+b)(a+b)=a2+2ab+b2\begin{align*} (a+b)^2 &= (a+b)(a+b) \\ &= a^2 + 2ab + b^2 \end{align*}

  3. f(x)=x2+2xf′(x)=2x+2\begin{align*} f(x) &= x^2 + 2x \\ f'(x) &= 2x + 2 \end{align*}

  4. ∣a+b∣≤∣a∣+∣b∣\begin{align*} |a + b| &\leq |a| + |b| \end{align*}

  5. E=mc2(1)E = mc^2 \tag{1}

  6. x+y=5x−y=1\begin{gather*} x + y = 5 \\ x - y = 1 \end{gather*}

In short

  • align* lines equations up at the &; \\ starts a new line.
  • A line that carries on starts with &=.
  • align and equation number lines; \tag{...} sets your own label; they need amsmath in a document.

Next, in lesson 11: words inside maths, and spacing.

Would you rather write it by hand?

LatexNotes turns a photo or PDF of your handwritten maths into LaTeX like this. Free to try, no sign-up.

Convert your handwriting to LaTeX →