Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The code below produces the following figure:

enter image description here

The issue I am having is that Sample is not vertically aligned, I get proper alignment if \cmidrule(l){2-3} \cmidrule(l){4-5} is removed.

How do I get proper alignment while maintaining the two horizontal lines?

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

\begin{table}[h]\centering
\begin{tabular}{lcccc}
\toprule 
\multirow{2}{*}{Sample} & \multicolumn{2}{c}{I} & \multicolumn{2}{c}{II} \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
 & A & B & C & D \\
\midrule
S1 & 5 & 8 & 12 & 2 \\
S2 & 6 & 9 & 2 & 6 \\
S3 & 7 & 9 & 5 & 8 \\
S4 & 8 & 9 & 8 & 2 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}
share|improve this question
1  
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  karlkoeller Jan 27 at 16:18
2  
Off topic: I would use \cmidrule(lr) instead of \cmidrule(l). –  Manuel Jan 27 at 16:36

1 Answer 1

up vote 4 down vote accepted

Use the optional argument of \multirow.

Substituting

\multirow{2}{*}{Sample}

with

\multirow{2}[3]{*}{Sample}

does what you want.

MWE:

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

\begin{table}[h]\centering
\begin{tabular}{lcccc}
\toprule
\multirow{2}[3]{*}{Sample} & \multicolumn{2}{c}{I} & \multicolumn{2}{c}{II} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
 & A & B & C & D \\
\midrule
S1 & 5 & 8 & 12 & 2 \\
S2 & 6 & 9 & 2 & 6 \\
S3 & 7 & 9 & 5 & 8 \\
S4 & 8 & 9 & 8 & 2 \\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

Output:

enter image description here

Note that I've also changed \cmidrule(l) to \cmidrule(lr) for a better looking table, as suggested by Manuel in the comments.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.