I want to be able to trim the left and the right of a \toprule
and \bottomrule
as you can do with \cmidrule(lr){<column range>}
. My attempted solution using \cmidrule[\heavyrulewidth]{<column range>}
comes pretty close, but unfortunately does not quite align vertically with what a \toprule
/\bottomrule
produces.
So, the desired output is the table on the left (which uses \MyToprule
and \MyBottomrule
), but with the vertical alignment of the table on the right (which uses \toprule
and \bottomrule
).
Note:
- This question was asked before as How to trim the length of \toprule?, but that was closed as a duplicate either because the title was not exactly what was desired or a workaround was sufficient.
- If there is an easier way to obtain the desired output that would be useful.
Code:
\documentclass{article}
\usepackage{booktabs}
\newcounter{MyCounter}
\newcommand*{\NumberRow}{\stepcounter{MyCounter}\arabic{MyCounter}.}%
\newcommand*{\MyToprule}[1]{% #1 = 2-<last column>
\cmidrule[\heavyrulewidth]{#1}%
}%
\newcommand*{\MyBottomrule}[1]{% #1 = 2-<last column>
\cmidrule[\heavyrulewidth]{#1}%
}%
\newenvironment{MyTabular}[2][]{%
\setcounter{MyCounter}{0}%
\tabular[#1]{#2}%
}{%
\endtabular
}%
\newcommand*{\TabularContent}{%
& Item Heading & Text Heading \\
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
\NumberRow & Item 1 & Some Text \\
& Item 1a & Some other Text \\
\NumberRow & Item 2 & Some Text \\
}%
\begin{document}
\begin{MyTabular}{cll}
\MyToprule{2-3}
&\multicolumn{2}{c}{Using MyToprule and MyBottomrule} \\
\TabularContent
\MyBottomrule{2-3}
\end{MyTabular}%
\begin{MyTabular}{cll}
\toprule
&\multicolumn{2}{c}{Using toprule and bottomrule} \\
\TabularContent
\bottomrule
\end{MyTabular}%
\end{document}