4

I've copied this source code from the section "Professional tables" in this page LaTeX/Tables, but the original source code is only for a table with 3 columns. I want to extend it to 5 columns, but only concatenate & does not work.

 \begin{tabular}{llr}
\hline

Gastro   & Grade 1 & Grade 2   & Grade 3   & Grade 4  \\
\hline
Gnat      & per gram    & 13.65    & Grade 3   & Grade 4  \\
          & each        & 0.01     & Grade 3   & Grade 4  \\
Gnu       & stuffed     & 92.50    & Grade 3   & Grade 4  \\
Emu       & stuffed     & 33.33     & Grade 3   & Grade 4 \\
Armadillo & frozen      & 8.99      & Grade 3   & Grade 4 \\
\hline
\end{tabular}

enter image description here

The last two columns overlap with the other columns. Do anyone have idea how to extend this source code to more columns?

5

Tables in LaTeX require a specification for the exact number of columns the table has. This is given in the argument to the \begin{tabular} environment.

In your table, you have specified {llr} which means the table has three columns. If you want five columns you need something like {llrll} (since your decimal column is the one you want right-aligned.)

For most tables, the booktabs package is really useful. It provides nicer vertical spacing and different width rules for tops and middle parts of the table. I've used it in the code below.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{llrll}
\toprule
Gastro   & Grade 1 & Grade 2   & Grade 3   & Grade 4  \\
\midrule
Gnat      & per gram    & 13.65    & Grade 3   & Grade 4  \\
          & each        & 0.01     & Grade 3   & Grade 4  \\
Gnu       & stuffed     & 92.50    & Grade 3   & Grade 4  \\
Emu       & stuffed     & 33.33     & Grade 3   & Grade 4 \\
Armadillo & frozen      & 8.99      & Grade 3   & Grade 4 \\
\bottomrule
\end{tabular}
\end{document}

Possible values for the column specification are:

l = left aligned column    
r = right aligned column
c = center aligned column
p{<width>} = left aligned column of <width>

There are more complex column specifications, but these are the basics. See the following questions for some more details:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.