0

The code

% arara: pdflatex

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{multirow}

\usepackage[table]{xcolor}
\rowcolors{2}{gray!25}{white}

\begin{document}

\begin{table}[htb]
\begin{tabular}{lS[table-format=2.1]S[table-format=2.1]}
\toprule
Fruit &
  {column 2} &
  {column 3} \\
\midrule
Banana                      & 80        & 90        \\
                            & 59.2(2)   &           \\
\rowcolor{gray!25}          & 6.8(3)    & 9.2(16)   \\
\multirow{-3}{*}{Apple}     & 21.1(1)   & 22.4(15)  \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

will produce:

enter image description here

What could be a viable way to vertically center the contents of the lower right table cell?

  1. I tried to make the grey row a single row and use a nested table for the multi-line contents. However, the S column type will no longer align the contents of the column at the decimal point.
  2. Also tried to fake the decimal point alignment by splitting each of the two data columns into three columns with the decimal point in the second column, respectively - seems to be a very ugly approach.
  3. Last resort would be to use a monospaced font in a cell with contents aligned right and use \phantom{...} to get everything aligned at the decimal points...

However, I think that there must be a more reasonable approach out there.

2
  • 2
    if the nested table uses an S column the numbers should align surely? Commented Mar 5, 2020 at 11:41
  • 1
    First of all, I'd start with correcting the table-format of the columns which currently does not take into account the uncertainty values and thus results in overfull box warnings. Something like S[table-format=2.1(2)] for the second column will help overcome this issue.
    – leandriis
    Commented Mar 5, 2020 at 11:45

1 Answer 1

1

Thanks to David Carlisle who pointed back at suggestion no. 1 from the original question. The following code seems to do the trick:

% arara: pdflatex

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{multirow}

\usepackage[table]{xcolor}
\rowcolors{2}{gray!25}{white}

\begin{document}

\begin{table}[htb]
\begin{tabular}{lS[table-format=2.1(2)]S[table-format=2.1(2)]}
\toprule
Fruit &
    {column 2} &
    {column 3} \\
\midrule
Banana & 
    80 &
    90 \\
Apple & 
    \begin{tabular}{S[table-format=2.1(2)]} 59.2(2) \\ 6.8(3) \\ 21.1(1) \end{tabular}  & 
    \begin{tabular}{S[table-format=2.1(2)]} 9.2(16) \\ 22.4(15) \end{tabular} \\
Pear & 
    \begin{tabular}{S[table-format=2.1(2)]} 8.1(19) \\ 88.8(18) \end{tabular} &
    \begin{tabular}{S[table-format=2.1(2)]} 3 \end{tabular} \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

It will produce:

enter image description here

Obviously, after hours of fiddling with something that doesn't work, it takes someone to tell you 'it must work' in order to get it right. I also thank leandriis who pointed out that the uncertainty values should be addressed within the definition of table-format.

1
  • The package dcolumn allows defining your own column formats for tables, including aligned decimal points/commas
    – vonbrand
    Commented Mar 6, 2020 at 20:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .