AMTH247 Lecture 4
LATEX -- Alignment
In this lecture we will look at various topics to do
with alignment -- tables, matrices and aligning equations.
Reading:
NSSI §2.11.5 and §3.5
User's Guide for the amsmath Package §3 and §4.1.
Tables are created with the tabular environment.
\begin{center}
\begin{tabular}{lcl}
Name & Date & Formula \\
Newton & 1687 & $F = m a$ \\
Einstein & 1905 & $E = m c^2$ \\
\end{tabular}
\end{center}
|
Name |
Date |
Formula |
|
Newton |
1687 |
|
|
Einstein |
1905 |
|
Notes:
- Tables are usually placed in the centre of the page, hence
the center environment.
- Directly after the
\begin{tabular} command, the
number and alignment of the columns in the table is
specified. The alignments are l - left,
c - center, and r - right. In our
example {lcl} specifies three columns with the indicated
alignments.
- Within each line of the table columns are separated by
an ampersand, &, and the line terminated by
\\.
- Vertical lines are indicated by a
| between
alignment specifiers.
- Horizontal lines are indicated by the command
\hline
at the appropriate position.
\begin{center}
\begin{tabular}{|l||cl|}
\hline
Name & Date & Formula \\
\hline
Newton & 1687 & $F = m a$ \\
Einstein & 1905 & $E = m c^2$ \\
\hline
\end{tabular}
\end{center}
|
Name |
Date |
Formula |
|
Newton |
1687 |
|
|
Einstein |
1905 |
|
Vertical spacing of tables can be altered by using changing
\arraystretch.
In the example below this is altered within the center
environment; if it were done outside the environment the change
would affect the whole document.
\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabular}{|l||cl|}
\hline
Name & Date & Formula \\
\hline
Newton & 1687 & $F = m a$ \\
Einstein & 1905 & $E = m c^2$ \\
\hline
\end{tabular}
\end{center}
|
Name |
Date |
Formula |
|
Newton |
1687 |
|
|
Einstein |
1905 |
|
The \multicolumn command can be used to to spread items
across columns of a table.
\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabular}{|l||cl|}
\hline
\multicolumn{3}{|c|}{Physics Formulas} \\
\hline
Name & Date & Formula \\
\hline
Newton & 1687 & $F = m a$ \\
Einstein & 1905 & $E = m c^2$ \\
\hline
\end{tabular}
\end{center}
|
Physics Formulas |
|
Name |
Date |
Formula |
|
Newton |
1687 |
|
|
Einstein |
1905 |
|
In this example
\multicolumn{3}{|c|}{Physics Formulas} \\
indicates that the entry should span 3 columns.
A \multicolumn line has its own vertical lines.
\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabular}{|l||cl|}
\multicolumn{3}{c}{Physics Formulas} \\
\hline
Name & Date & Formula \\
\hline
Newton & 1687 & $F = m a$ \\
Einstein & 1905 & $E = m c^2$ \\
\hline
\end{tabular}
\end{center}
|
Physics Formulas |
|
Name |
Date |
Formula |
|
Newton |
1687 |
|
|
Einstein |
1905 |
|
The array environment is used to align mathematical formulas
and works in much the same way as the tabular environment.
$$ \mathbf{A} = \left[ \begin{array}{cccc}
a_{11} & a_{12} & \ldots & a_{1n} \\
a_{21} & a_{22} & \ldots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \ldots & a_{mn}
\end{array} \right] $$
$$ y = \left\{ \begin{array}{rcc}
-1 & \text{for} & x < 0 \\
0 & \text{for} & x = 0 \\
1 & \text{for} & x > 0
\end{array} \right. $$
Note the use of \right. as an invisible right bracket
and the use of right alignment of the first column.
In the next two subsections we will see alternative ways
of doing these examples using the amsmath package.
The amsmath package provides a convenient way
of formatting matrices.
There are a number of different environments which enclose
matrices in different types of braces:
| Environment |
Braces |
| matrix |
None |
| pmatrix |
 |
| bmatrix |
![$ [ \; ]$](img6.gif) |
| Bmatrix |
 |
| vmatrix |
 |
| Vmatrix |
 |
As for tables and arrays, the matrix elements are separated by
& and the line terminated by \\.
Unlike tables and arrays, matrices do not need alignment specifiers.
$$ \mathbf{A} = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6
\\ 7 & 8 & 9 \end{pmatrix} $$
$$ \mathbf{A} = \begin{bmatrix}
a_{11} & a_{12} & \ldots & a_{1n} \\
a_{21} & a_{22} & \ldots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \ldots & a_{mn} \\
\end{bmatrix} $$
The following example shows how to use the cases
environment.
Note the use of \quad spacing.
$$ y = \begin{cases}
-1 &\text{for} \quad x < 0 \\
\hfill 0 &\text{for} \quad x = 0 \\
\hfill 1 &\text{for} \quad x > 0 \\
\end{cases} $$
Standard LATEX has a eqnarray environment for
aligning equations, (see NSSI §3.5), but the amsmath
align environment is more convenient.
The align environment produces numbered equations,
the examples below use align* which leaves equations
unnumbered.
Our first example aligns the
symbols:
\begin{align*}
x &= r \cos \theta \\
y &= r \sin \theta
\end{align*}
The following structure is common:
\begin{align*}
I &= \int_{0}^{\pi} \sin t dt \\
&= \left[- \cos t \right]_{0}^{\pi} \\
&= - \cos \pi + \cos 0 \\
&= 2
\end{align*}
The \intertext command allows text to interspersed with equations
while maintaining the alignment.
\begin{align*}
I &= \int_{0}^{\pi} \sin t dt \\
\intertext{which is easily integrated}
&= \left[- \cos t \right]_{0}^{\pi} \\
&= - \cos \pi + \cos 0 \\
&= 2
\end{align*}
The \align environment can also create multiple aligned
columns where the ampersand doubles as an alignment point
and as a column separator.
In this example the first and third ampersands on each line
are alignment points while the second ampersand on each line
is a column separator.
\begin{align*}
\frac{d}{dx} \sin x &= \cos x
& \frac{d}{dx} e^x &= e^x \\
\frac{d}{dx} \cos x &= - \sin x
& \frac{d}{dx} \log x &= \frac{1}{x} \\
\end{align*}
AMTH247 Lecture 4
LATEX -- Alignment
This document was generated using the
LaTeX2HTML translator Version 2K.1beta (1.61)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split +0 lecture.tex
The translation was initiated by amth247 on 2003-03-17
amth247
2003-03-17