\cmidrule not properly horizontally aligned on the outer edges & less vertical space between text lines
I find it useful to trim 1em from the left and not trim at all from the right side of the cmidrule
. I also included Steven Segletes suggestions. Here the first code, I also made the second and the third column centered, which I think look better; also I used bottomrule
for the last rule
\documentclass{article}
\usepackage{booktabs}
\usepackage{array,multirow}
\renewcommand\arraystretch{1.2}
\setlength{\tabcolsep}{15pt}
\begin{document}
\begin{table}
\begin{tabular}{@{}lcc@{}}
\toprule
Samples & \multicolumn{2}{c}{Observations}\\
\cmidrule(l{1em}){2-3}
&New & Old\\[-2pt]
&Region & Region \\
\midrule
Sample 1&1&5\\
Sample 2&2&6\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Also, if you know the width of the column, you could try using multirow for "New region" and "old Region". It could be risky but you can try:
\documentclass{article}
\usepackage{booktabs}
\usepackage{array,multirow}
\renewcommand\arraystretch{1.2}
\setlength{\tabcolsep}{15pt}
\begin{document}
\begin{table}
\begin{tabular}{@{}lcc@{}}
\toprule
Samples & \multicolumn{2}{c}{Observations}\\
\cmidrule(l{1em}){2-3}
&\multirow{2}{1cm}{New Region} &\multirow{2}{1cm}{Old Region}\\
& & \\
\midrule
Sample 1&1&5\\
Sample 2&2&6\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Since you're using booktabs
, you needn't reset \arraystretch
manually, it does it for you. To adjust the \cmidrule
, use @{\hspace{30pt}}
before the second column specification and no need for (lr)
settings. Notice that 30pt=2*15pt=2\tabcolsep
.
\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
%\renewcommand\arraystretch{1.2}
\renewcommand{\tabcolsep}{15pt}
\begin{document}
\begin{table}
\begin{tabular}{@{}l@{\hspace{30pt}}ll@{}}
\toprule
Samples & \multicolumn{2}{l}{Observations} \\ \cmidrule{2-3}
& New & Old \\
& Region & Region \\ \midrule
Sample 1 & 1 & 5 \\
Sample 2 & 2 & 6 \\
\midrule[\heavyrulewidth]
\end{tabular}
\end{table}
\end{document}
The “excess” space is not unexpected, because you're setting \tabcolsep
to 15pt, instead of the default 6pt.
The default amount of trimming is \cmidrulekern
, at the outset 0.5em, unless you specify l{<dimen>}
or r{<dimen>}
. So, at 10pt size, the trimming is about the same as the default \tabcolsep
(remember that space of the amount of \tabcolsep
is inserted at the left and right of a column, unless countermanded by @{<tokens>}
.
The problem on the right side is that you trim notwithstanding the trailing @{}
, so the rule will be short of the right edge by \cmidrulekern
.
The space between the header rows is due to \arraystretch
being set to 1.2. You can shorten it if you set the header cells in a nested tabular
with a standard \arraystretch
.
\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\renewcommand\arraystretch{1.2}
\setlength{\tabcolsep}{15pt}
\newcommand{\splitcell}[2][c]{%
\begingroup
\renewcommand{\arraystretch}{1}%
\begin{tabular}{@{}#1@{}}
#2
\end{tabular}%
\endgroup
}
\begin{document}
\begin{table}
\begin{tabular}{@{} lll @{}}
\toprule
Samples & \multicolumn{2}{l@{}}{Observations} \\
\cmidrule(l{\tabcolsep}){2-3}
& \splitcell[l]{New \\ Region} & \splitcell[l]{Old \\ Region} \\
\midrule
Sample 1&1&5\\
Sample 2&2&6\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Final notes: \tabcolsep
must be set with \setlength
, differently from \arraystretch
(which is not a length, but a factor). The bottom rule should not be \midrule[\heavyrulewidth]
, but simply \bottomrule
.