2

I have a table with numbers which get aligned using the S column type from siunitx. Some numbers are put into \multirow and with the \tablenum macro the alignment works perfectly as long as the columns are only as wide as required by the numbers. But when some text is added in the cells which forces the columns to strech the alignment gets lost, see example.

Is this a bug? Or should I just abandon multirow altogether? :-)

\documentclass{article}
\usepackage{multirow,siunitx}
\begin{document}

\begin{tabular}{S[table-format=2.2]S[table-format=2.2]S[table-format=1.2]}
{Energy} & {Efficiency} & {Uncertainty} \\
14.14 & 10.41 & 3.82 \\
22.10 & 4.17 & 3.14 \\
\multirow{2}*{\tablenum{30.97}} & 1.31 & \multirow{2}*{\tablenum{3.08}} \\
& 1.48 &  \\
\end{tabular}

\end{document}

Here is the output:

output

4

enter image description here

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\newbox\mybox
\sbox\mybox{\begin{tabular}{@{}S[table-format=2.2]@{}}1.31\\1.48\end{tabular}}
\begin{tabular}{S[table-format=2.2]S[table-format=2.2]S[table-format=1.2]}
{Energy} & {Efficiency} & {Uncertainty} \\
14.14 & 10.41 & 3.82 \\
22.10 & 4.17 & 3.14 \\
% oops 30.97 &{\begin{tabular}{@{}S[table-format=2.2]@{}}1.31\\1.48\end{tabular}}& 3.08 \\
30.97 &{\usebox{\mybox}}& 3.08 \\
\end{tabular}

\end{document}
1

The \tablenum command relies on begin able to 'bump' into the side of the column, which can only work if the natural width of the column is maintained all the way down. With a longer header you are going to have to add some dummy digit space to help alignment. For example

\documentclass{article}
\usepackage{multirow,siunitx}
\begin{document}

\begin{tabular}{S[table-format=3.3]S[table-format=2.2]S[table-format=5.5]}
{Energy} & {Efficiency} & {Uncertainty} \\
14.14 & 10.41 & 3.82 \\
22.10 & 4.17 & 3.14 \\
\multirow{2}*{\tablenum[table-format=3.3]{30.97}} & 1.31 & \multirow{2}*{\tablenum[table-format=5.5]{3.08}} \\
& 1.48 &  \\
\end{tabular}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.