# How can I center text vertically in the middle of a multicolumn table cell?

When I enter this, why does the 'Type I stuff' and 'Type II stuff' break down into 2-3 lines? How can I have them written in one line without linebreak? When I use c instead of M for the multicolumn, it doesn't center the text in the vertical middle of the cell. How can I change that?

\documentclass[a4paper,12pt]{scrartcl}
\usepackage{array}
\usepackage{hhline}
\usepackage{xfrac}

\begin{document}
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.10\linewidth-2\tabcolsep}}
\begin{table}[h]
\centering
\caption{Long Stuff}

\begin{tabular}{|l|MMMM|MMMM|M}
\hline
Primer &  \multicolumn{4}{M|}{Type I stuff} &  \multicolumn{4}{M|}{Type II stuff} \\[5pt] \hline
Type I &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  \\[5pt] \hline
Type II &  undiluted   &  $\sfrac{1}{10}$   &  $\sfrac{1}{100}$   &    $\sfrac{1}{1000}$ &  undiluted   &   $\sfrac{1}{10}$  &  $\sfrac{1}{100}$   &   $\sfrac{1}{1000}$  \\[5pt] \hline
\end{tabular}
\end{table}
\end{document}


• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– user31729
Apr 24 '15 at 7:42

Non-centring comes from the \\[5pt] used before \hlines. I replace this with loading the cellspace package, which ensures minimal vertical spacing above and below cels in columns with a specifier prefixed with the letter S (or C if you use siunitx). I also load the caption package to ensure a correct vertical spacing between caption and table:

\documentclass[preview]{article}

\usepackage{amsmath, xfrac}
\usepackage{caption}
\usepackage{cellspace}
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.10\linewidth-2\tabcolsep}}

\begin{document}

\begin{table}[h]
\caption{Dilutions used to establish positive and negative controls}
\label{Dilutions used to establish positive and negative controls}
\begin{tabular}{|Sl|*{4}{M}|*{4}{M}|M}
\hline
Primer & \multicolumn{4}{c|}{Type I stuff} & \multicolumn{4}{c|}{Type II stuff} \\ \hline
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\\hline
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \hline
\end{tabular}
\end{table}

\end{document}


Use \makecell from the equally named package (i.e. makecell) However, this command has to specified for each cell individually. The default setup is to center it vertically.

There is some issue with the \\[5pt] commands, which results in some upshift of the fractions in the last column. I added a second version in which this does not occur

\documentclass{article}

\usepackage{array}
\usepackage{hhline}
\usepackage{mathtools}
\usepackage{makecell}

\usepackage{xfrac}

\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.12\linewidth-2\tabcolsep}}

%\newcolumntype{Q}[1]{>{\centering\arraybackslash}m{\dimexpr.10\linewidth-2\tabcolsep}}

\begin{document}

\begin{table}[h]
\centering
\caption{Dilutions used to establish positive and negative controls}
\label{Dilutions used to establish positive and negative controls}
\begin{tabular}{|l|MMMM|MMMM|M}
\hline
Primer &  \multicolumn{4}{M|}{\makecell{Type I stuff}} &  \multicolumn{4}{M|}{\makecell{Type II stuff}} \\[5pt] \hline
Type I &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  \\[5pt] \hline
Type II &  undiluted   &  $\sfrac{1}{10}$   &  $\sfrac{1}{100}$   &    $\sfrac{1}{1000}$ &  undiluted   &   $\sfrac{1}{10}$  &  $\sfrac{1}{100}$   &   $\sfrac{1}{1000}$  \\[5pt] \hline
\end{tabular}
\end{table}

\begin{table}[h]

\centering
\caption{Dilutions used to establish positive and negative controls}
\label{Dilutions used to establish positive and negative controls}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|l|MMMM|MMMM|M}
\hline
Primer &  \multicolumn{4}{M|}{\centering\makecell{Type I stuff}} &  \multicolumn{4}{M|}{\makecell{Type II stuff}} \\ \hline
Type I &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  & $\sfrac{1}{1000}$   \\ \hline
Type II &  undiluted   &  $\sfrac{1}{10}$   &  $\sfrac{1}{100}$   &    $\sfrac{1}{1000}$ &  undiluted   &   $\sfrac{1}{10}$  &  $\sfrac{1}{100}$  &  $\sfrac{1}{1000}$  \\ \hline
\end{tabular}
\end{table}

\end{document}


I suggest you delete the manual [5pt] spacing directives and, instead, specify

\setlength\extrarowheight{5pt}


I'd also switch to from the m to the p column type to assure that the material in the first column is set on the same baseline as in the other 8 columns.

Furthermore, I'd like to encourage you switching to a table design that uses no vertical lines and fewer, but well-spaced horizontal lines, as is exemplified in the second table below. It uses the line-drawing macros of the booktabs package.

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{tabularx}
\newcolumntype{M}{>{\centering\arraybackslash}p{\dimexpr.10\linewidth -2\tabcolsep}}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\usepackage{hhline}
\usepackage{xfrac}

\usepackage{booktabs}

\begin{document}
\begin{table}[h]
\setlength\extrarowheight{5pt}
\centering
\caption{Long Stuff}

\begin{tabular}{|l|MMMM|MMMM|}
\hline
Primer &  \multicolumn{4}{c|}{Type I stuff} &  \multicolumn{4}{c|}{Type II stuff} \\ \hline
Type I &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  \\ \hline
Type II &  undiluted   &  $\sfrac{1}{10}$   &  $\sfrac{1}{100}$   &    $\sfrac{1}{1000}$ &  undiluted   &   $\sfrac{1}{10}$  &  $\sfrac{1}{100}$   &   $\sfrac{1}{1000}$  \\ \hline
\end{tabular}
\end{table}

\begin{table}[h]
\setlength\extrarowheight{3pt}
\centering
\caption{Version with booktabs-based horizontal rules and no vertical rules}

\begin{tabularx}{0.92\textwidth}{@{} l *{8}{C} @{}}
\toprule
Primer &  \multicolumn{4}{c}{Type I stuff} &  \multicolumn{4}{c}{Type II stuff} \\
\cmidrule(lr){2-5} \cmidrule(l){6-9}

Type I &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  &  undiluted   &   $\sfrac{1}{10}$  &   $\sfrac{1}{100}$  &   $\sfrac{1}{1000}$  \\
Type II &  undiluted   &  $\sfrac{1}{10}$   &  $\sfrac{1}{100}$   &    $\sfrac{1}{1000}$ &  undiluted   &   $\sfrac{1}{10}$  &  $\sfrac{1}{100}$   &   $\sfrac{1}{1000}$  \\ \bottomrule
\end{tabularx}
\end{table}
\end{document}

• using \extrarowheight makes cells non-vertically centred. Apr 24 '15 at 9:47
• @Bernard - the point of the second solution is, in part, to show that when fewer horizontal lines are drawn, it's no longer necessary to spend time on the fairly pointless activity of assuring that the cell contents are centered vertically. :-)
– Mico
Apr 25 '15 at 0:41
• I completely agree with you. Apr 25 '15 at 1:20