Improve your tables with booktabs

Besides the overall beauty of LaTeX, I was never really satisfied with the table environment. The vertical rules are quite useless in most cases and not exactly eye candy. There is a must have package called booktabs, which helps you improve the quality of your LaTeX tables. It gets rid of the vertical rules, as well as the double rules. It introduces varying rule thicknesses and extra spacing to make it look cleaner. In order to understand every detail of booktabs, read the package documentation. However it often suffices to only know the basics, which will be explained here.

The table environment is called with

\usepackage{booktabs}
...
\begin{tabular}{llr}
...
\end{tabular}

This is used for a 3-column table, where the first two columns are aligned left and the last column is aligned right.

The horizontal rules are called with \toprule, \midrule and \bottomrule. These commands are pretty self-explanatory. Note that the top and bottom rules are slightly thicker than the mid rule. This gives a neat look.

The content of the tables is filled in the same manner as you are used to. As an example, reproduce the following table:

\begin{tabular}{llr}
\toprule
First name & Last Name & Grade \\
\midrule
John & Doe & $7.5$ \\
Richard & Miles & $2$ \\
\bottomrule
\end{tabular}

The result is already a lot better than a standard LaTeX table. To make it even better, notice that the first two columns are related to each other. Using the command \cmidrule, a rule will span a certain amount of columns. In our case, we’d like to span column 1 and 2 and the rule should be aligned right: \cmidrule(r){1-2}. The spanned columns will be named ‘Name’, so we have

\begin{tabular}{llr}
\toprule
Name \\
\cmidrule(r){1-2}
First name & Last Name & Grade \\
\midrule
John & Doe & $7.5$ \\
Richard & Miles & $2$ \\
\bottomrule
\end{tabular}

As a final detail, we would like to center the ‘Name’ text. This is done with:

\begin{tabular}{llr}
\toprule
\multicolumn{2}{c}{Name} \\
\cmidrule(r){1-2}
First name & Last Name & Grade \\
\midrule
John & Doe & $7.5$ \\
Richard & Miles & $2$ \\
\bottomrule
\end{tabular}

Download

You can download all the code above in a zip file.

6 Comments

  1. Oscar Rosero says:

    When I use this package, sometimes I get thicker top and bottom rules, but sometimes I don’t. I do not know why is this happening. Is there any way to solve this?

    • Michel says:

      “\toprule” and “\bottumrule” are thicker lines then “\cmidrule” or “\midrule”
      But the visibility on a screen is reduced as the lines are just 1pixel on your screen. However you will notice the difference when you print the document.

  2. Mladen says:

    Why do people always assume I am Neo and can “see” code :)
    Lets assume I am a googler who happened to stumble upon this very nice thing here. The reason I am goggling is I don’t know how to do something because my Latex skills are poor, and more Latex without pictures wont help me to take Your code. Thanks anyway.

  3. Etienne Gregoire says:

    In our case, we’d like to span column 1 and 2 and the rule should be aligned right: \cmidrule(r){1-2}.

    This is actually wrong, the (r) specifies the trimming (i.e. terminating the cmidrule before the end of the column) and not the alignment.

    Thank you for your documentation!

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>