[Tex/LaTex] How to trim the length of \toprule?

booktabsrulestables

How to trim \toprule (from booktabs package)?

It is probably something basic I'm missing, but I need it and it's nowhere to be found.

Best Answer

If I understand your objective correctly, you want the lines generated by \toprule -- and by \midrule and \bottomrule too, right? -- start at the left-hand edge and end at the right-hand edge of the contents of the table.

To achieve this objective, you could specify @{} as the first and last items in the argument of a tabular, tabular*, tabularx, etc. environment:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\noindent
\begin{tabular}{ @{} lccr @{} } % @{} suppresses the whitespace in the corresponding position
\toprule
long story & about & absolutely & nothing \\
\midrule
aa & bb & cc & dd\\
\multicolumn{2}{@{}l}{First thoughts \dots }\\     % note the @{} item before "l"
& & \multicolumn{2}{r@{}}{\dots Final thoughts}\\  % note the @{} item after "r"
\bottomrule
\end{tabular}
\end{document}

enter image description here

The MWE also illustrates that if your table has \multicolumn directives that encompass the first or final columns of the table, you'll again need to supply @{} items, as appropriate, this time in the second argument of the \multicolumn command.

By the way, I believe that suppressing the whitespace at the far left and far right edges of a table is something that the author of the booktabs package recommends doing; see, e.g., the tabular environment at the top of page 5 of the package's user guide; the output of that code is shown on p. 2 of the guide.

Related Question