[Tex/LaTex] Modifying specialrule to cover fewer columns

tables

In LaTeX tables, is there a way to modify \specialrule to cover only few columns or should I just use \cmidrule? Thanks

Best Answer

According to the booktabs manual (section 5 page 6), the trimming of toprule, midrule, bottomrule and specialrule is available if you typeset your tabular using longtable.

If you have both booktabs and longtable packages loaded, the booktabs rule commands can now all be used exactly as described above, within a longtable. There is an addition worth noting: within a longtable, you can use the optional left and right trimming commands, which normally only work for \cmidrules, with \toprule, \midrule and \bottomrule (and if you must, also with \specialrule). Users who hacked the previous release for longtable com- patability6 seemed to like all the rules to be right trimmed 0.5 em. I think you can do the same by making @{} be the last column specier. Still, after working out the rest of the code, it was easy to add parsing for the optional arguments, so I did. (I didn't go the whole way and allow the optional trimming outside a longtable; this would be a huge amount of work. If you must have trimmed rules, make all your tables be longtables!)

As you will see, you change the number inside the parenthesis (l{<len>}r{<len>}). You may calculate the length with dimexpr or calc, but unless all your columns is of fixed width (or manually calculated), you probably have to do some eyeballing and trials before you find the right trimming factor. I added some colour as a bonus.

Using \cmidrule[wd](trim){a-b} is another option, both in longtable and ordinary tabular.

longtable is a stable and advanced package. And it is no problem to typeset all your tables as longtables. However, be aware that longtable does not float, so never place a longtable inside a table environment. So if you need floating tables, use \cmidrule. However, then neither \toprule, \specialrule nor \bottomrule can be trimmed in an tabularenvironment.

enter image description here

\documentclass{article}
\usepackage{longtable, array, booktabs}
\usepackage[table]{xcolor}
\begin{document}
    \begin{longtable}{@{}lccccr@{}}

\toprule
head&head&head&head&head&head\\
\midrule
\endfirsthead
\toprule
head&head&head&head&head&head\\
\midrule
\endhead
\bottomrule
\endfoot
\bottomrule
\endlastfoot

abcd&efgh&abcd&efgh&abcd&efgh\\
\midrule
abcd&efgh&abcd&efgh&abcd&efgh\\
\arrayrulecolor{red}
\specialrule{3pt}{2pt}{2pt}(l{3em}r{4em})
\arrayrulecolor{black}
abcd&efgh&abcd&efgh&abcd&efgh\\
\midrule
abcd&efgh&abcd&efgh&abcd&efgh\\
\arrayrulecolor{green!50!black}
\cmidrule[3pt](l{\tabcolsep}r{\tabcolsep}){2-5}
\arrayrulecolor{black}
abcd&efgh&abcd&efgh&abcd&efgh\\
\end{longtable}
\end{document}
Related Question