# Problems with \toprule and \midrule in a table

Having the following siunitx table code in LyX, for each occurrence of \toprule and \midrule I obtain an error message:

The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., hobx'), type I' and the correct spelling (e.g., I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.

I correctly imported siunitx in the preamble.
TexLive version: 2012.10.20121205_r28449.fc18

LaTeX code:

\centering
\sisetup{output-decimal-marker={,}}

\begin{tabular}{ccS}
\toprule
{Dimensione finestra} & {Perdita} & {Tempo}\\
{} & {} & {(secondi)}\\
\midrule
10                & 0$\%$       & 121\\
\midrule
10                & 10$\%$       & 127\\
\midrule
10                & 20$\%$       & 176\\
\midrule
10                & 30$\%$       & 257\\
\midrule
10                & 40$\%$       & 442\\
\midrule
10                & 50$\%$       & 780\\
\midrule
10                & 60$\%$       & 1226\\
\midrule
10                & 70$\%$       & 1469\\
\midrule
10                & 80$\%$       & 1904 \\
\midrule
10                & 90$\%$       & 3234 \\
\midrule
50                & 0$\%$        & 46 \\
\midrule
50                & 10$\%$       &109 \\
\midrule
50                & 20$\%$       &146 \\
\midrule
50                & 30$\%$       &202 \\
\midrule
50                & 40$\%$       &257 \\
\midrule
50                & 50$\%$       &373 \\
\midrule
50                & 60$\%$       &544 \\
\midrule
50                & 70$\%$       &760 \\
\midrule
50                & 80$\%$       &1356 \\
\midrule
50                & 90$\%$       &6588 \\
\midrule
100                & 0$\%$       &76 \\
\midrule
100                & 10$\%$       &91 \\
\midrule
100                & 20$\%$       &109 \\
\midrule
100                & 30$\%$       &146 \\
\midrule
100                & 40$\%$       &180 \\
\midrule
100                & 50$\%$       &297 \\
\midrule
100                & 60$\%$       &414 \\
\midrule
100                & 70$\%$       &585 \\
\midrule
100                & 80$\%$       &1355 \\
\midrule
100                & 90$\%$       &4326 \\

\bottomrule
\end{tabular}

-
Please include your preamble, so other people can try to compile your example. My guess is you need to load the booktabs package as well. – Psirus Jan 22 '13 at 10:50
\usepackage{graphicx} \usepackage{siunitx} – Caterpillar Jan 22 '13 at 10:53
Thank you Psirus, it worked \usepackage{booktabs} If you put an official answer I can give you the mark – Caterpillar Jan 22 '13 at 10:55
– Claudio Fiandrino Jan 22 '13 at 11:04

\midrule is a command defined by the Booktabs package. Include \usepackage{booktabs} in your preamble to typeset your table.

-
So is \toprule, which is what was giving me a similar error (Undefined control sequence). – Scott Weldon Mar 4 '15 at 5:11

\usepackage{booktabs}


solved the problem :O

-

You should certainly load the booktabs package in order to enable the use of \toprule, \midrule, and \bottomrule.

You should also aim to improve the readability of the table. You could start by getting rid of all interior \midrule statements, which add lots of visual clutter without making the table easier to read. In addition, do consider (a) adding a bit of whitespace after the end of 10th and 20th row by inserting an \addlinespace statement, (b) formatting the entries in the first two columns more elegantly by assigning them type S instead of c, and (c) moving the shared \% elements from the cells in the second column to the corresponding header.

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}

\centering
\sisetup{output-decimal-marker={,}}
\begin{tabular}{S[table-format=3.0]
S[table-format=2.0]
S[table-format=4.0]}
\toprule
{Dimensione finestra} & {Perdita} & {Tempo}\\
{} & {(\%)} & {(secondi)}\\
\midrule
10                & 0        & 121\\
10                & 10       & 127\\
10                & 20       & 176\\
10                & 30       & 257\\
10                & 40       & 442\\
10                & 50       & 780\\
10                & 60       & 1226 \\
10                & 70       & 1469 \\
10                & 80       & 1904 \\
10                & 90       & 3234 \\
50                & 0        & 46 \\
50                & 10       &109 \\
50                & 20       &146 \\
50                & 30       &202 \\
50                & 40       &257 \\
50                & 50       &373 \\
50                & 60       &544 \\
50                & 70       &760 \\
50                & 80       &1356 \\
50                & 90       &6588 \\
100                & 0        & 76 \\
100                & 10       & 91 \\
100                & 20       &109 \\
100                & 30       &146 \\
100                & 40       &180 \\
100                & 50       &297 \\
100                & 60       &414 \\
100                & 70       &585 \\
100                & 80       &1355 \\
100                & 90       &4326 \\
\bottomrule
\end{tabular}
\end{document}


The following screenshot shows the tabular environment with the proposed modifications on the left, and without the modifications (i.e., what would result just from loading the required booktabs package) on the right. Note, inter alia, the better centering of the numbers in the third column, which was achieved by specifying S[table-format=4.0] instead of just S`.

I hope you will agree that the table on the left is more readable than the one on the right.

-