About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-12-13: Ebook sale (12th December 2024 – 1st January 2025): cybercrime fiction short stories Unsocial Media and Smile for the Camera free; crime fiction short story The Briefcase free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99.


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:

\tabularnewline

[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.
<recently read> \endtemplate

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}

Image showing typeset output (click here for a more detailed description).

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:

Image: as the previous example except that the word
Total has appeared in bold

Let's add an extra column and a header row:

\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:

Image showing typeset output (click here for a more detailed description).

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:

Image: as the second example but the decimal points
are aligned


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.

Terms of Use Privacy Policy Cookies Site Map FAQs