Further amsmath
alignments
In addition to the align*
environment shown in the main lesson, amsmath
has several other display math constructs, notably gather
for multi-line displays that do not need alignment, and multline
for splitting a larger single expression over multiple lines, aligning the first line to the left, and the last to the right. In all cases the *
form omits the equation numbers by default.
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
Gather
\begin{gather}
P(x)=ax^{5}+bx^{4}+cx^{3}+dx^{2}+ex +f\\
x^2+x=10
\end{gather}
Multline
\begin{multline*}
(a+b+c+d)x^{5}+(b+c+d+e)x^{4} \\
+(c+d+e+f)x^{3}+(d+e+f+a)x^{2}+(e+f+a+b)x\\
+ (f+a+b+c)
\end{multline*}
\end{document}
Columns in math alignments
The amsmath
alignment environments are designed to take pairs of columns with the first column of each pair aligned to the right and the second aligned to the left. This allows multiple equations to be shown, each aligned towards its relation symbol.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
Aligned equations
\begin{align*}
a &= b+1 & c &= d+2 & e &= f+3 \\
r &= s^{2} & t &=u^{3} & v &= w^{4}
\end{align*}
\end{document}
In addition there are variants of the display environments ending in ed
that make a subterm inside a larger display. For example, aligned
and gathered
are variants of align
and gather
respectively.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
Aligned:
\[
\left.\begin{aligned}
a&=b\\
c&=d
\end{aligned}\right\}
\Longrightarrow
\left\{\begin{aligned}
b&=a\\
d&=c
\end{aligned}\right.
\]
\end{document}
aligned
takes a positional optional argument similar to tabular
. This is often useful to align an inline math formula on its top row; compare the items in the list in the following example.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
\begin{itemize}
\item
$\begin{aligned}[t]
a&=b\\
c&=d
\end{aligned}$
\item
$\begin{aligned}
a&=b\\
c&=d
\end{aligned}$
\end{itemize}
\end{document}
Bold Math
Standard LaTeX has two methods to give bold symbols in math. To make an entire expression bold, use \boldmath
before entering the expression. The command \mathbf
is also available to set individual letters or words in upright bold roman.
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\begin{document}
$(x+y)(x-y)=x^{2}-y^{2}$
{\boldmath $(x+y)(x-y)=x^{2}-y^{2}$ $\pi r^2$}
$(x+\mathbf{y})(x-\mathbf{y})=x^{2}-{\mathbf{y}}^{2}$
$\mathbf{\pi} r^2$ % bad use of \mathbf
\end{document}
If you want to access bold symbols (as would be used by \boldmath
) within an otherwise normal weight expression, then you can use the command \bm
from the bm
package. Note that \bm
also works with symbols such as =
and Greek letters. (Note that \mathbf
has no effect on \pi
in the example above.)
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{bm}
\begin{document}
$(x+\mathbf{y})(x-\mathbf{y})=x^{2}-{\mathbf{y}}^{2}$
$(x+\bm{y})(x-\bm{y}) \bm{=} x^{2}-{\bm{y}}^{2}$
$\alpha + \bm{\alpha} < \beta + \bm{\beta}$
\end{document}
Mathtools
The package mathtools
loads amsmath
and adds several additional features, such as variants of the amsmath
matrix environments that allow the column alignment to be specified.
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\begin{document}
\[
\begin{pmatrix*}[r]
10&11\\
1&2\\
-5&-6
\end{pmatrix*}
\]
\end{document}
Unicode Math
As will be seen in Lesson 14, there are variant TeX engines that use OpenType fonts. By default, these engines still use classic TeX math fonts but you may use the unicode-math
package to use OpenType Math fonts. The details of this package are beyond this course and we refer you to the package documentation. However, we give a small example here.
% !TEX lualatex
\documentclass[a4paper]{article}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
\begin{document}
One two three
\[
\log \alpha + \log \beta = \log(\alpha\beta)
\]
Unicode Math Alphanumerics
\[A + \symfrak{A}+\symbf{A}+ \symcal{A} + \symscr{A}+ \symbb{A}\]
\end{document}