[Tex/LaTex] Vertical alignment in multirow environment

multirowshortstacktables

I'm using a multirow environment to span text over two rows. As it does not support \\ for inserting a line break, I'm nesting it into a shortstack (see MWE below). However, the text is in neither of both cases (single line text, dual line text) really centered. What am I doing wrong?

Example Image

The red line indicates the center of the heading row (spans over two rows). As shown in the image, neither of both lines are really vertically centered.

enter image description here

MWE

\documentclass[a4paper,twocolumn]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{multirow}

\usepackage[a4paper,top=3cm,bottom=2cm,left=1.5cm,right=1.5cm,marginparwidth=1.75cm]{geometry}

\title{Your Paper}
\author{You}

\begin{document}
    \begin{table}[htbp]
        \caption{Classifier configurations and their performance.}
        \label{tblClassifierConfig}
        \begin{tabular*}{1.2\columnwidth}{@{\extracolsep{\fill}}lrllll@{}}
        \toprule
        \multirow{2}{*}{\raisebox{-\heavyrulewidth}{\shortstack[l]{\textbf{N-gram}\\as Range}}} & \multirow{2}{*}{\raisebox{-\heavyrulewidth}{\shortstack[l]{\textbf{Vocab. Size}\\in \#n-grams}}} & \multicolumn{2}{c}{Test Set 1} & \multicolumn{2}{c}{Test Set 2} \\ 
        \cmidrule(l){3-6} &  & \textbf{Prec.} & \textbf{Recall} & \textbf{Prec.} & \textbf{Recall} \\ \midrule
        (2,4)-char                        & 500                                 & 0.9999         & 0.9999          & 0.5085         & 0.5849          \\
        (2,4)-char                        & 1000                                & 0.9999         & 0.9999          & 0.5114         & 0.6132          \\
        (2,3)-word                        & 1,500                               & 0.9999         & 0.9999          & 0.5134         & 0.6268          \\
        (1,3)-word                        & 2,000                               & 0.9999         & 0.9999          & 0.5138         & 0.6307          \\ \bottomrule
        \end{tabular*}
    \end{table}
\end{document}

Best Answer

in multirow cells you also need to consider vertical space introduced by \cmidrule. it is about 0.4 row height, so you can wrote

 \multirow{2.4}{*}{ ...}

i also suggest in columns with numbers to use S column type from siunitx package, not increase table width (it will protrude in next column). istead this rather reduce tabocolsep:

\documentclass[a4paper,twocolumn,english]{article}

\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage{booktabs, makecell, multirow}
\usepackage{siunitx}
\usepackage[a4paper,
            top=3cm,bottom=2cm,left=1.5cm,right=1.5cm,
             marginparwidth=1.75cm]{geometry}
\usepackage{lipsum}

\title{Your Paper}
\author{You}

\begin{document}
\lipsum[11]
\begin{table}[htbp]
    \caption{Classifier configurations and their performance.}
    \label{tblClassifierConfig}
    \setlength\tabcolsep{0pt}
    \begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}}
                            l
                             S[table-format=4.0,
                               group-four-digits,
                               group-separator=\,]
                        *{4}{S[table-format=1.4]}
                                   }
    \toprule
    \multirow{2.4}{*}{\makecell{\textbf{N-gram}\\as Range}} 
        & {\multirow{2.4}{*}{\makecell{\textbf{Vocab. Size}\\in \#n-grams}}}
            & \multicolumn{2}{c}{Test Set 1} 
                & \multicolumn{2}{c}{Test Set 2} \\
    \cmidrule{3-4} 
    \cmidrule{5-6}
        &  & {\textbf{Prec.}} & {\textbf{Recall}} & {\textbf{Prec.}} & {\textbf{Recall}} \\ 
    \midrule
    (2,4)-char  &   500 & 0.9999    & 0.9999    & 0.5085    & 0.5849            \\
    (2,4)-char  & 1 000 & 0.9999    & 0.9999    & 0.5114    & 0.6132            \\
    (2,3)-word  & 1 500 & 0.9999    & 0.9999    & 0.5134    & 0.6268            \\
    (1,3)-word  & 2 000 & 0.9999    & 0.9999    & 0.5138    & 0.6307            \\ 
    \bottomrule
    \end{tabular*}
\end{table}
\end{document}

which gives

enter image description here

Related Question