## 4.6.1 Column and Row Separation

Remember the special characters? The ampersand character & is used to separate column entries. Rows are separated using:

\\[<vertical space>]

where <vertical space> is extra vertical spacing between rows, if required. There is also a longer equivalent:

[Alignment tab changed to \cr]If you have used something like >{\raggedright}p{<length>} as the specifier for your last column, you must use \tabularnewline instead of \\ to indicate the row break otherwise you will get the following error:

! Extra alignment tab has been changed to \cr.


Example:

Let's have two columns, the first left justified and the second right justified:

\begin{tabular}{lr}
Video & 8.99\\
CD & 9.11\\
DVD & 15.00\\
Total & 33.10
\end{tabular}

Recall from §2. Some Definitions that LaTeX ignores spaces at the start of a line and treats multiple spaces as a single space, so I could just have easily done:

\begin{tabular}{lr}
Video & 8.99\\
CD    & 9.11\\
DVD   & 15.00\\
Total & 33.10
\end{tabular}

and still have got the same result, but now the code is easier to read.

Entries form implicit grouping, so declarations made within a tabular environment only have an effect up to the next & or \\.

Example:

\begin{tabular}{lr}
Video & 8.99\\
CD    & 9.11\\
DVD   & 15.00\\
\bfseries Total & 33.10
\end{tabular}

Output:

\begin{tabular}{lrr}
Item  & ex VAT & inc VAT\\
Video &   8.99 &  10.56 \\
CD    &   9.11 &  10.70 \\
DVD   &  15.00 &  17.63 \\
\bfseries Total &  33.10 &  39.89
\end{tabular}

Output:

Example (Aligning on a Decimal Point):

If you want to align on the decimal point, it's best to use the siunitx package. That's beyond the scope of this book, but for simple data this can be achieved using the @ inter-column specifier. For example:

\begin{tabular}{lr@{.}l}
Video & 8 & 99\\
CD    & 9 & 11\\
DVD   & 15 & 00\\
\bfseries Total & 33 & 10
\end{tabular}

Output:

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.