[Tex/LaTex] Vertical alignment using multirow and booktabs

booktabsmultirowtablesvertical alignment

I'm trying to format correctly the following table:

\documentclass[a4paper,twoside]{report}
\usepackage{array,colortbl,multirow,multicol,booktabs,ctable}
\newcommand{\hdrule}{\midrule[\heavyrulewidth]}
\usepackage[english]{babel}
\usepackage{xunicode}
\usepackage[no-math]{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{ccccccc>{\itshape}r}
\toprule
a & b & c & d & e & f & g & 1 \\ \hdrule
\multirow{4}{*}{A} & \multirow{4}{*}{B} & \multirow{4}{*}{C} & \multirow{4}{*}{D} & \multirow{2}{*}{E} & F & G & 2 \\ \cmidrule{6-8}
&&&&& H & I & 3 \\ \cmidrule{5-8}
&&&& J & K & L & 4 \\ \cmidrule{5-8}
&&&& M & N & --- & 5 \\ \hdrule
--- & --- & --- & --- & O & P & Q & 6 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

I use the package booktabs for the horizontal rules, and it seems that it messes up the vertical centering as calculated by multirow. For instance, A B C and D should be aligned with the rule separating lines 2 and 3, and E should be aligned with the rule separating lines 1 and 2. Instead, it is slightly higher.

Is there any way around this?

Best Answer

For fine tunning the vertical position, you can use the second optional argument of \multirow:

\documentclass[a4paper,twoside]{report}
\usepackage{array,colortbl,multirow,multicol,booktabs,ctable}
\newcommand{\hdrule}{\midrule[\heavyrulewidth]}
\usepackage[english]{babel}
\usepackage{xunicode}
\usepackage[no-math]{fontspec}
%\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{ccccccc>{\itshape}r}
\toprule
a & b & c & d & e & f & g & 0 \\ \hdrule
\multirow{5}{*}[-2pt]{A} & \multirow{5}{*}[-2pt]{B} & \multirow{5}{*}[-2pt]{C} & \multirow{5}{*}[-2pt]{D} & \multirow{2}{*}[-3pt]{E} & F & G & 1 \\ \cmidrule{6-8}
&&&&& H & I & 2 \\ \cmidrule{5-8}
&&&& J & K & L & 3 \\ \cmidrule{5-8}
&&&& M & N & --- & 4 \\ \hdrule
--- & --- & --- & --- & O & P & Q & 5 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

I commented out the line \setmainfont just because I don't have that font.

Related Question