# Vertical alignment using multirow and booktabs

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?

-
Please always post complete code and not just snippets. Where does \hdrule come from? – Gonzalo Medina Aug 10 '12 at 2:30
Sorry about that, I've edited with a working example. It includes the definition of \hdrule (which is a big \midrule) – arnaudrg Aug 10 '12 at 2:35

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}


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

-
Yep, that does the trick, thanks! Just for information, I suppose there is no simple way to do this automatically? – arnaudrg Aug 10 '12 at 2:49
@arnaudrg in this case, I don't think there's an automatic way. – Gonzalo Medina Aug 10 '12 at 2:54

Additional remark: you \usepackage{ctable}, but you don't use it. Here is an alternative and cleaner way to do this (you don't need array, colortbl, multicol, booktabs, babel, and xunicode here):

%!xelatex
\documentclass[a5paper,twoside]{report}
\usepackage{multirow,ctable}
\usepackage[no-math]{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\begin{document}

\ctable[pos = ht,caption = ctable version]{ccccccc>{\itshape}r}{}{\FL
a & b & c & d & e & f & g & 0 \ML
\multirow{5}{*}[-2pt]{A} & \multirow{5}{*}[-2pt]{B} & \multirow{5}{*}[-2pt]{C} & \multirow{5}{*}[-2pt]{D} & \multirow{2}{*}[-3pt]{E} & F & G & 1 \NN \cmidrule{6-8}
&&&&& H & I & 2 \NN \cmidrule{5-8}
&&&& J & K & L & 3 \NN \cmidrule{5-8}
&&&& M & N & --- & 4 \ML[\heavyrulewidth]
--- & --- & --- & --- & O & P & Q & 5 \LL
}

\end{document}

-