2

Here are my example and the code.

enter image description here

\begin{table}[H] 
\begin{tabular}{lrrrr}
\toprule
\multirow{2}[3]{*}{Method} & \multicolumn{2}{c}{group} &  \multicolumn{2}{c}{variable} \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
 & rate & size & rate & size \\
\midrule
s = 1/2 & 0.7668 (0.0058) & 8.78 (0.086)  & 0.7184 (0.0067) & 11.07 (0.098) \\
s = 1/4 & 0.7768 (0.0066) & 12.81 (0.099) & 0.6732 (0.0063) & 15.29 (0.103) \\
\bottomrule
\end{tabular} 
\end{table}

My question is rather simple. I wish to keep the column names (rate, size) in the second row centered, while the numbers in the table aligned to right. How could I achieve that? Moreover, how to use cmidrule, especially what does its first option do? I tried to change to \cmidrule{lr} and cmidrule{r}, but seems no difference to me.

Thanks for the help.

2 Answers 2

2
  • \multicolumnn can also be used for a single column to overwrite the column specification.

  • The first argument of \cmidrule specifies some trimming. The example uses (lr). Then you will see, the line is also shorter at the right side.

Example:

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
\begin{table}
\begin{tabular}{lrrrr}
\toprule
\multirow{2}[3]{*}{Method} & \multicolumn{2}{c}{group} &
\multicolumn{2}{c}{variable} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
 & \multicolumn{1}{c}{rate}
 & \multicolumn{1}{c}{size}
 & \multicolumn{1}{c}{rate}
 & \multicolumn{1}{c}{size} \\
\midrule
s = 1/2 & 0.7668 (0.0058) & 8.78 (0.086)  & 0.7184 (0.0067) & 11.07 (0.098)
\\
s = 1/4 & 0.7768 (0.0066) & 12.81 (0.099) & 0.6732 (0.0063) & 15.29 (0.103)
\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

Result

0
2

With help of `makecell˙package is really simple: enter image description here

Code:

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{multirow,booktabs,makecell}
\renewcommand\theadfont{\normalfont}

    \begin{document}
\begin{table}
    \begin{tabular}{lrrrr}
\toprule
\multirow{2}[3]{*}{Method} & \multicolumn{2}{c}{group} &  \multicolumn{2}{c}{variable} \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
 & \thead{rate} & \thead{size} & \thead{rate} & \thead{size} \\
\midrule
s = 1/2 & 0.7668 (0.0058) & 8.78 (0.086)  & 0.7184 (0.0067) & 11.07 (0.098) \\
s = 1/4 & 0.7768 (0.0066) & 12.81 (0.099) & 0.6732 (0.0063) & 15.29 (0.103) \\
\bottomrule
    \end{tabular}
\end{table}
    \end{document}
0

You must log in to answer this question.

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