(click anywhere to close)

[LaTeX] Math Environments II

category: Writing | course: LaTeX Math | difficulty:

Last chapter discussed, among others, the displaymath and equation environment. Anywhere within these, you can use the sub environments I’ll discuss in this chapter. Most of these change the numbering or alignment of the equation(s) one way or another, but their applications are endless. So to speak, of course – there are limits, silly you.

When I first wrote this article, everything in here was a pure sub environment - it wouldn't work if it wasn't inside a core math environment. But, as time progresses, some things have changed, and some things were added, which means half of these math environments actually stand on their own. Check what type the environment is in the examples, or you'll meet lots of errors.

These 8 sub environments are: subequations, multline, split, align, flalign, alignat, gather, and cases.

But, these aren’t supported by default, which means you need to include the amsmath package. Basic LaTeX actually doesn’t support too many mathematical commands, which is why the AMS-LaTeX packages were invented by the American Mathematical Society, of which amsmath is the most extensive. Most of the things that are going to be explained in this entire course require one of the AMS packages, remember that!

Subequations

This one is actually quite confusing. A subequation contains equations, which are numbered with letters affixed to the end of the equation number.

\begin{subequations}
$$5x + 6y = 10$$
$$2x + y = 5$$
\end{subequations}


Multline & Split

The multline environment allow you to split equations over multiple lines – which isn’t possible in normal math mode – by using the familiar newline command: \\. It aligns the start of the equation with the left margin, and the end with the right margin.

The split environment does roughly the same, but centres the equations, and also aligns the multiple lines by means of the ampersand ( & ) character.

\begin{multline}
5x + 6y = 10\\
2x + y = 5
\end{multline}
\hrulefill
$$\begin{split} 5x + 6y &= 10\\ 2x + y &= 5 \end{split}$$


It's multline, not multiline (as you'd expect, because it allow multiple lines). Very annoying. There are often better alternatives than this.

Align & Flalign

The align environment does the same as the split environment, but with two important differences.

Firstly, the split environment is not supposed to go together with any other typeset material on the same line, while the align environment can be used next to other (unaligned) elements.

Secondly, there's extra added space above and below the equations to make them stand out more.

Actually, this environment is the improved version of an old and obsolete core environment, which means it also doesn't need to be placed inside one to work.

But, if you don't want that much space around your align environment, you can use the aligned alternative. It has an optional parameter with values t (top) or b (bottom), which can be used to force vertical placement of the equation number. Semantically, align should be used for multiple equations, while aligned should be used for a single equation over multiple lines.

\begin{align}
5x + 6y &= 10\\
2x + y &= 5
\end{align}
\hrulefill
\begin{aligned}[b] 5x + 6y &= 10\\ 2x + y &= 5 \end{aligned}


The flalign environment stands for full align, which simply means that the leftmost and rightmost columns are pushed against the margins, making the environment the full width of the text.

Alignat

The alignat environment also does the same, and groups the columns in left-right pairs – first column is right aligned, second is left aligned, third is right aligned, and so on. It has one required argument, which is the amount of pairs. The main difference is that it doesn't add any white space, which means you need to do that yourself (if you want that, which you probably do). It also has the semantically different variation that needs to be within a core environment, alignedat.

%The quad is used to separate the columns with some whitespace
\begin{alignat}{2}
5x + 6y \quad &= 10 \quad & a^2 + b^2 \quad &=c^2 \\
2x + y  \quad &= 5  \quad & a^3 + b^3 \quad &=c^3
\end{alignat}


Gather

The gather environment centres all equations you put in, separated by a newline. The name comes from the fact that it gathers all equations around the centre.

\begin{gather}
5x + 6y = 10\\
2x + y = 5\\
a^2 + b^2 = c^2\\
a^3 + b^3 = c^3
\end{gather}


Cases

The cases environment allows you to provide multiple cases for a single function, which means it’s mostly useful for piecewise functions. Different cases are separated by newlines, and aligned with the familiar ampersands.

$f(x) = \begin{cases} x &\mbox{if } x = 0 \\ 5x & \mbox{if } x \not= 0 \end{cases} \pmod{2}.$


Removing Equation Numbers

All of these environments also have a starred variation that leaves out the equation tag. Simply add an asterisk to the end of the environment name in both the begin and end command! An example:

\begin{align*}
5x + 6y &= 10\\
2x + y &= 5
\end{align*}


If you, however, want some equations within the same environment numbered, and not some others, you can use \nonumber on those specific lines.

It’s also possible to customize the equation numbers, or sometimes called equation tags, by using the \tag{text} command. If you want no tag, it's simply \notag.

\begin{align*}
5x + 6y &= 10 \tag{Equation Uno} \\
2x + y &= 5 \tag{Equation Duo}
\end{align*}

CONTINUE WITH THIS COURSE
Do you like my tutorials?
To keep this site running, donate some motivational food!
Crisps
(€2.00)
Chocolate Milk
(€3.50)
Pizza
(€5.00)