9

The \cmidrule in booktabs package has trim option to specify how much to trim from left or right. However from the following example \cmidrule(l{2pt}r{2pt}){1-2} shows the line is shifted, not shortened; I may be confused about the this trim option, but I expected 2 points from left and right should be removed (trimmed).

The next code \cmidrule(l{2pt}r{2pt}){3-3} is even more confusing to show that the line is shifted to the left.

How to interpret the trim option with \cmdrule?

enter image description here

\documentclass[12pt]{article}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{@{}llr@{}}
\toprule
    \multicolumn{2}{c}{Item} &\multicolumn{1}{c}{Price/lb} \\
\cmidrule(r){1-2}\cmidrule(l){3-3}
    a & b & c \\
\cmidrule(l{2pt}r{2pt}){1-2}\cmidrule(l{2pt}r{2pt}){3-3}
\morecmidrules
\cmidrule(l{2pt}r{2pt}){2-3}
\addlinespace[5pt]
    Food& Category & \multicolumn{1}{c}{\$}\\
\midrule
    Apples & Fruit  & 1.50 \\
    Oranges & Fruit & 2.00 \\
\addlinespace
    Beef & Meat     & 4.50 \\
\specialrule{.5pt}{3pt}{3pt}
    x & y & z \\
\bottomrule
\end{tabular}

\end{document}
1
  • I don't know whether my answer answers your question. I think you're confused by the look of the \cmidrules since you're not using a \tabcolsep on the outer edges of the first/last column. That is, you're using @{} to suppress it.
    – Werner
    Commented Oct 31, 2016 at 16:44

3 Answers 3

4

Your interpretation of the trim option is correct. What seems confusion here is the fact that removed the column space on the outer edges of your tabular.

When considering the tabular version without the end \tabcolsep removed

\begin{tabular}{ l l r }

enter image description here

the adjustments for \cmidrule using the left and right trim options seem more in line with what one would expect.


The default trim, if not specified explicitly is \cmidrulekern which is set to .5em. This equates to 5pt under the 10pt (default) document class option, 5.475pt under 11pt and 5.87494pt under 12pt. Perhaps, instead of specifying trims in absolute values, is a font-related width like em.

1

Without any parameters, the default value for the trim seems to be larger than 2pt to cause the confusion.

When I changed the code not to have any trimming with the following code, I can get the expected trimmed result.

\cmidrule(l{0pt}r{0pt}){1-2}\cmidrule(l{0pt}r{0pt}){3-3}

enter image description here

2
  • 1
    Yes, the default trim value is \cmidrulekern which is set to .5em. You can just use \cmidrule{1-3} instead of specifying a 0pt trim on all sides.
    – Werner
    Commented Oct 31, 2016 at 17:16
  • If this is "the answer to your question", I don't understand how it relates to your question.
    – Werner
    Commented Oct 31, 2016 at 18:01
0

In version 2021N (2021-09-01), tabularray package added support for trim options in its booktabs library.

The library provides ratio values for trim options l, r, and lr: the possible values of these three options are decimal numbers between -1 and 0. The product of the number and colsep is the dimension to be trimmed.

Therefore, if you use @{} to remove colsep, there will be no trimming and no shifting of cmidrule.

Note that you need to put trim options l, r, and lr inside square brackets with tabularry.

\documentclass[12pt]{article}

\usepackage{booktabs}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\section{booktabs package}

\begin{tabular}{@{}llr@{}}
\toprule
    \multicolumn{2}{c}{Item} &\multicolumn{1}{c}{Price/lb} \\
\cmidrule(r){1-2}\cmidrule(l){3-3}
    a & b & c \\
\cmidrule(l{2pt}r{2pt}){1-2}\cmidrule(l{2pt}r{2pt}){3-3}
\morecmidrules
\cmidrule(l{2pt}r{2pt}){2-3}
\addlinespace[5pt]
    Food& Category & \multicolumn{1}{c}{\$}\\
\midrule
    Apples & Fruit  & 1.50 \\
    Oranges & Fruit & 2.00 \\
\addlinespace
    Beef & Meat     & 4.50 \\
\specialrule{.5pt}{3pt}{3pt}
    x & y & z \\
\bottomrule
\end{tabular}

\section{booktabs library in tabularray package}

\begin{booktabs}{
  colspec = {@{}llr@{}},
  cell{1}{1} = {c=2}{c}, % multicolumn
  cell{1}{3} = {c},
  cell{3}{3} = {c},
}
\toprule
  Item    &          & Price/lb \\
\cmidrule[r]{1-2}\cmidrule[l]{3}
  a       & b        & c        \\
\cmidrule[lr=-0.5]{1-2}\cmidrule[lr=-0.5]{3}
\morecmidrules
\cmidrule[lr=-0.5]{2-3}
\addlinespace[5pt]
  Food    & Category & \$       \\
\midrule
  Apples  & Fruit    & 1.50     \\
  Oranges & Fruit    & 2.00     \\
\addlinespace
  Beef    & Meat     & 4.50     \\
\specialrule{.5pt}{3pt}{3pt}
  x       & y        & z        \\
\bottomrule
\end{booktabs}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .