# Wrapping or adding line breaks in header cell of siunitx's S-type column

When using the siunitx package, is it possible to either "wrap" or insert line breaks in the header cell of an S-type column (see Section 4.6 of the documentation)?

I have a relatively long table wherein I'd like to do this.

Below, I show the general usage of the S-type column. Then, I (kind of) mimic what what to achieve using a p-type column, but it would be nice to be able to wrap the header while taking advantage of siunitx's S-type column.

MWE:

\documentclass[12pt]{article}
\usepackage{siunitx, booktabs}
\sisetup{per-mode=symbol}
\setlength\parindent{0em}
\begin{document}
\begin{tabular}{@{}cSSS@{}}
\toprule
&
{Reaction 1 (\si{\mmol\per\s})} &
{Reaction 2 (\si{\umol\per\minute})} &
{Reaction 3 (\si{\pmol\per\hour})} \\
\midrule
Item 1 & 10 & 12 & 15 \\
Item 2 & 20 & 22 & 25 \\
Item 3 & 30 & 32 & 35 \\
\bottomrule
\end{tabular}
\par\bigskip
\begin{tabular}{@{}cp{2cm}p{2cm}p{2cm}@{}}
\toprule
&
{Reaction 1 (\si{\mmol\per\s})} &
{Reaction 2 (\si{\umol\per\minute})} &
{Reaction 3 (\si{\pmol\per\hour})} \\
\midrule
Item 1 & 10 & 12 & 15 \\
Item 2 & 20 & 22 & 25 \\
Item 3 & 30 & 32 & 35 \\
\bottomrule
\end{tabular}
\end{document}


## 2 Answers

You can nest any construct that allows linebreaking (a tabular or \parbox, or here I use \shortstack for a change)

\documentclass[12pt]{article}
\usepackage{siunitx, booktabs}
\sisetup{per-mode=symbol}
\setlength\parindent{0em}
\begin{document}
\begin{tabular}{@{}cSSS@{}}
\toprule
&
{\shortstack{Reaction 1\\(\si{\mmol\per\s})}} &
{\shortstack{Reaction 2\\(\si{\umol\per\minute})}} &
{\shortstack{Reaction 3\\(\si{\pmol\per\hour})}} \\
\midrule
Item 1 & 10 & 12 & 15 \\
Item 2 & 20 & 22 & 25 \\
Item 3 & 30 & 32 & 35 \\
\bottomrule
\end{tabular}

\end{document}

• \tabular and \parbox give me error messages. \shortstack doesn't, but it vertically aligns the last line of the cell with the first line of the cells in the other columns, which is ugly. Frankly, I'm baffled why siunitx doesn't try to reproduce the functionality of p columns. – oulenz May 12 at 18:23

\shortstack didn't work for me, so I used

\mbox{\specialcell{\textbf{24 GiB}\\\textbf{96 processors}}}


where \specialcell was defined by egreg in How to add a forced line break inside a table cell as

\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}


Example:

\usepackage{siunitx}

\begin{table}
\begin{tabular}{|c|c|c|S[table-format=4.2]|S[table-format=4.2]|}
\textbf{Mount option} & \textbf{Backend API} & \specialcell{\textbf{MPI hint}\\\textbf{configuration}} & \mbox{\specialcell{\textbf{12 GiB}\\\textbf{(48 processors)}}} & \mbox{\specialcell{\textbf{24 GiB}\\\textbf{(96 processors)}}} \\
% ...
\end{tabular}
\end{table}


which results in: