# How to vertically centre a cell spanning multiple rows with the p column type

Bit of a mouthful of a question title

I have the following table:

I'm not completely convinced it's the absolute best way to display this information, but I'm reproducing a table that is laid out like this, with a few minor improvements, such as removing ugly vertical lines. I would be open to suggestions as to how I could improve the look though.

Anyway, my question is how to get "Train formation" to be vertically centred.

You can see the problem is that it spans two rows, the permissible speed row and the row underneath. But the row underneath is a p type row consisting of three lines, but not three rows.

I have produced the above image using:

\multirow{4}{*}{\textbf{Train formation}}


But I'm not too sure whether that takes into account that there aren't actually four rows, there are only two. It's just that the second row is three lines long. I've also set \renewcommand{\arraystretch}{1.25}

And similarly I wouldn't be sure how to vertically align the two 10 mph (15 kph) entries. As you can see, I have made use of the fact that I happen to have three rows, each of which is two lines long. But If one of those rows were to be only one line long, how would I vertically centre the second and third column?

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}

\usepackage[detect-weight=true]{siunitx}
\DeclareSIUnit{\mph}{mph}

\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}

\renewcommand{\arraystretch}{1.25}
\setlength{\tabcolsep}{0.8em}

\begin{document}

\begin{center}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{0.4\textwidth}
>{\centering\arraybackslash}p{0.15\textwidth}
>{\centering\arraybackslash}p{0.15\textwidth}@{}}
\toprule
\multicolumn{1}{@{}c}{\multirow{4}{*}{\textbf{Train formation}}} &
\multicolumn{2}{c@{}}{\textbf{Permissible speed}} \\ \cmidrule{2-3}
& \textbf{\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) or above} &
\textbf{\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) or less} \\ \midrule
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do \\
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad &
\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) &
\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) \\
minim veniam, quis nostrud exercitation ullamco laboris nisi ut \\
\bottomrule
\end{tabular}
\end{center}

\end{document}


A slightly improved layout (from my point of view), using a decimal number for the number of ‘rows’ (which are actually lines, as you noticed), and the m{...} specifier in the place of p{...}. I also simplified the code with the \km abbreviation and the {=} width argument for \multirow.

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}

\usepackage[detect-weight=true]{siunitx}
\DeclareSIUnit{\mph}{mph}

\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}

\renewcommand{\arraystretch}{1.25}
\setlength{\tabcolsep}{0.8em}

\begin{document}

\begin{center}
\begin{tabular}{@{}>{\raggedright\arraybackslash}m{0.4\textwidth}
>{\centering\arraybackslash}m{0.15\textwidth}
>{\centering\arraybackslash}m{0.15\textwidth}@{}}
\toprule
\multirow{4.5}{=}{\centering\textbf{Train formation}}
&
\multicolumn{2}{c@{}}{\textbf{Permissible speed}} \\ \cmidrule{2-3}
& \textbf{\SI{10}{\mph} (\SI{15}{\km\per\hour}) or above} &
\textbf{\SI{10}{\mph} (\SI{15}{\km\per\hour}) or less} \\ \midrule
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do \\
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad &
\SI{10}{\mph} (\SI{15}{\km\per\hour}) &
\SI{10}{\mph} (\SI{15}{\km\per\hour}) \\
minim veniam, quis nostrud exercitation ullamco laboris nisi ut \\
\bottomrule
\end{tabular}
\end{center}

\end{document}


• How did you generate the 4.5 value for your multirow? I have a second table, similarly laid out, but with two rows of two lines each (so just get rid of minim veniam, quis nostrud exercitation ullamco laboris nisi ut). Would 2.5 do just as well here? – Au101 Jan 31 at 20:01
• By trial and error (taking into account the values of \aboverule sep and \belowrulesep, and the \cmidrule thickness). – Bernard Jan 31 at 20:06

Since we know the widths of the columns, one can put a tabular inside a tabular and get the columns to align.

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}

\usepackage[detect-weight=true]{siunitx}
\DeclareSIUnit{\mph}{mph}

\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}

\renewcommand{\arraystretch}{1.25}
\setlength{\tabcolsep}{0.8em}

\begin{document}

\begin{center}
\begin{tabular}{@{}>{\raggedright\arraybackslash}p{0.4\textwidth}
>{\centering\arraybackslash}p{0.15\textwidth}
>{\centering\arraybackslash}p{0.15\textwidth}@{}}
\toprule
\centering\textbf{Train formation} &
\multicolumn{2}{c@{}}{\begin{tabular}{@{}>{\centering\arraybackslash}p{0.15\textwidth}
>{\centering\arraybackslash}p{0.15\textwidth}@{}}
\multicolumn{2}{c@{}}{\textbf{Permissible speed}} \\ \midrule
\textbf{\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) or above} &
\textbf{\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) or less}
\end{tabular}} \\ \midrule
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do \\
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad &
\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) &
\SI{10}{\mph} (\SI{15}{\kilo\metre\per\hour}) \\
minim veniam, quis nostrud exercitation ullamco laboris nisi ut \\
\bottomrule
\end{tabular}
\end{center}

\end{document}


• Ended up using a bit of both answers, thanks! – Au101 Jan 31 at 21:59