[Tex/LaTex] Center a multirow

multirowtablesvertical alignment

I'm unable to center a table's multirow vertically (it works only horizontally):

\def\arraystretch{1.5}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{table}[t]
    \caption{Caption.}
    \label{table:label}

    \begin{tabularx}{\columnwidth}{| Y | Y | X | X |}
        \hline
         & OA & Acc & Time [minutes] \\
        \hline 

        \multirow{2}{*}{\hfil A} & \multirow{2}{*}{100\%} & 100\% & x \\
        \cline{3-4}
         & & 100\% & y \\
        \hline

        \multirow{2}{*}{B} & & 100\% & 100\% \\
        \cline{3-3}
         & - & Urban areas: 100\% & \\
        \hline
    \end{tabularx}
\end{table}

Best Answer

What is important for multirow is not the number of rows it has to encompass, but the number n of lines. These may be different for cells in paragraph mode like p,m, b or X. Changing the value of \arraystretch also makes the computation of equivalent lines more complex. Since version 2.0, if I remember well, multirow accepts a number of lines with decimal values, which makes it easier to fine-tune the vertical position of the contents. Here, I should have taken n=3, but n=2.8 yields a better result.

Unrelated: I replaced the hyphen in the last \multirow, which is irrelevant here, with a more correct endash. Also I loaded caption to have a decent spacing between caption and table.

    \documentclass{article}
    \usepackage{ragged2e}
    \usepackage{multirow, tabularx, caption}
    \captionsetup{skip=6pt}
    \newcolumntype{Y}{>{\centering\arraybackslash}X}

    \begin{document}

    \def\arraystretch{1.5}
    \begin{table}[t]
    \caption{Caption.}
    \label{table:label}
    \begin{tabularx}{\columnwidth}{| Y | Y | *{2}{ >{\RaggedRight\arraybackslash}X |}}
        \hline
         & OA & Acc & Time [minutes] \\
        \hline
        \multirow{2}{*}{A} & \multirow{2}{*}{100\,\%} & 100\,\% & x \\
        \cline{3-4}
         & & 100\% & y \\
        \hline
        \multirow{2.8}{*}{ B} &\multirow{2.8}{*}{–} & 100\,\% & 100\,\% \\
        \cline{3-3}
         & & Urban areas: 100\,\% & \\
        \hline
    \end{tabularx}
    \end{table}

    \end{document} 

enter image description here

Related Question