0

I'm trying to align a table with has a mix of numbers in scientific notation and common notation. Many of these have associated errors in parenthesis. siunitx has a feature - \num{}- which allows to write scientific notation and errors in a neat way. I've used siunitx before to correctly align table and it has worked flawlessly. Unfortunately, it seems that siunitx doesn't work very well with its own \num{} feature when it comes to alignment. I've tried sisetup=detect-all=true but to no avail.

Any insight/help would be greatly appreciated! MWE can be found below

\documentclass[a4paper]{article}

\usepackage{siunitx}
\usepackage{threeparttable}
\usepackage{caption}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table*}
    \begin{threeparttable}[!htb]

        \captionsetup{font=scriptsize} % sets caption size for the table
        \caption{Experimental spectroscopic parameters for the two observed rotamers of phenylephrine obtained from CP-FTMW spectra}
        \label{chp6:tb2} % should go after \caption
        \setlength{\tabcolsep}{0pt}
        \sisetup{table-align-text-post=false,detect-all=true}
        \begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}} ll *{2}{S[table-format=-4.5(2)]} @{} }
            \toprule
            &   & {Rotamer $I$}  & {Rotamer $II$}   \\
            \midrule
            \multirow{3}{*}{LA-CP-FMTW} &$A$ & \num{2094.0113(113)} & \num{1908.0283(405)}\\                           &$B$          & \num{468.35153(101)} & \num{452.29425(85)} \\                                     
            &$C$         & \num{411.50542(117)} & \num{412.59360(74)} \\
            &$\Delta_{J}$& \num{-1.53(53)d-5} & {-}  \\
            &$\Delta_{K}$& \num{2.59(38)d-2} & {-}  \\
            &$N$         & 59 & 36 \\
            &$\sigma$    & 29  & 29  \\
            \midrule
            \multirow{3}{*}{LA-MB-FTMW} &$A$           & \num{2094.10270(107)} & \num{1908.1532(188)}\\
            &$B$           & \num{468.35339(8)}    & \num{452.29545(11)}\\
            &$C$           & \num{411.50313(8)}    & \num{412.59709(10)}\\
            &$\chi_{aa}$   & \num{2.7267(218)}     & \num{2,6753(129)}\\
            &$\chi_{bb}$   & \num{-2.6047(159)}    & \num{-3,9435(134)}\\
            &$\chi_{cc}$   & \num{-0.1219(159)}    & \num{1,2681(134)}\\
            &$N$           & 18                    & 20 \\
            &$\sigma$      & 1.2                   & 1.5 \\
            \midrule
            \multirow{3}{*}{Theoretical}&$A$& 2069    & 1860 \\                                 
            &$B$& 470    & 455 \\                                 
            &$C$& 413    & 417 \\
            &$\chi_{aa}$& 2.76 & 2.73\\
            &$\chi_{bb}$& -2.40 & -319\\
            &$\chi_{cc}$& -0.36 &0.46\\
            \bottomrule
        \end{tabular*}
    \begin{tablenotes}\scriptsize\smallskip\raggedright
            \item to be concluded
        \end{tablenotes}
    \end{threeparttable}
\end{table*}
\end{document}
4
  • Out of curiosity: Is \num{d-5} equivalent to \num{e-5}? Feb 12, 2020 at 9:40
  • Just out of curiosity: For the cells in the two S-type columns, why do you encase the numbers in \num wrappers?
    – Mico
    Feb 12, 2020 at 9:47
  • 1
    @FelixEmanuel by default siunitx uses the following markers for exponents: dDeE, so yes, d is the same as e.
    – Skillmon
    Feb 12, 2020 at 9:53
  • @Mico I was using siunitx to write down scientific notation with errors. Since both the alignment and the \num environment belong to the same package, I didn't think it would do any harm - after all, seemed logical to use tables with \num
    – Strelok
    Feb 12, 2020 at 10:00

2 Answers 2

3

Don't use \num inside of table columns using S, if you want alignment let S handle the input. The S type columns will use the same routine as \num for the data anyway.

The following aligns your columns without a single \num:

\documentclass[a4paper]{article}

\usepackage{siunitx}
\usepackage{threeparttable}
\usepackage{caption}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table*}
    \begin{threeparttable}[!htb]

        \captionsetup{font=scriptsize} % sets caption size for the table
        \caption{Experimental spectroscopic parameters for the two observed rotamers of phenylephrine obtained from CP-FTMW spectra}
        \label{chp6:tb2} % should go after \caption
        \setlength{\tabcolsep}{0pt}
        \sisetup{table-align-text-post=false,detect-all=true}
        \begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}} ll
          S[table-format=-4.5(3)e-1,group-digits=false]
          S[table-format=4.5(3),group-digits=false] @{} }
            \toprule
            &   & {Rotamer $I$}  & {Rotamer $II$}   \\
            \midrule
            \multirow{3}{*}{LA-CP-FMTW} &$A$ & 2094.0113(113) & 1908.0283(405)\\                           &$B$          & 468.35153(101) & 452.29425(85) \\                                     
            &$C$         & 411.50542(117) & 412.59360(74) \\
            &$\Delta_{J}$& -1.53(53)d-5 & {-}  \\
            &$\Delta_{K}$& 2.59(38)d-2 & {-}  \\
            &$N$         & 59 & 36 \\
            &$\sigma$    & 29  & 29  \\
            \midrule
            \multirow{3}{*}{LA-MB-FTMW} &$A$           & 2094.10270(107) & 1908.1532(188)\\
            &$B$           & 468.35339(8)    & 452.29545(11)\\
            &$C$           & 411.50313(8)    & 412.59709(10)\\
            &$\chi_{aa}$   & 2.7267(218)     & 2,6753(129)\\
            &$\chi_{bb}$   & -2.6047(159)    & -3,9435(134)\\
            &$\chi_{cc}$   & -0.1219(159)    & 1,2681(134)\\
            &$N$           & 18                    & 20 \\
            &$\sigma$      & 1.2                   & 1.5 \\
            \midrule
            \multirow{3}{*}{Theoretical}&$A$& 2069    & 1860 \\                                 
            &$B$& 470    & 455 \\                                 
            &$C$& 413    & 417 \\
            &$\chi_{aa}$& 2.76 & 2.73\\
            &$\chi_{bb}$& -2.40 & -319\\
            &$\chi_{cc}$& -0.36 &0.46\\
            \bottomrule
        \end{tabular*}
    \begin{tablenotes}\scriptsize\smallskip\raggedright
            \item to be concluded
        \end{tablenotes}
    \end{threeparttable}
\end{table*}
\end{document}

enter image description here

EDIT: As per your request, a variant that doesn't align exponents:

\documentclass[a4paper]{article}

\usepackage{siunitx}
\usepackage{threeparttable}
\usepackage{caption}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table*}
    \begin{threeparttable}[!htb]

        \captionsetup{font=scriptsize} % sets caption size for the table
        \caption{Experimental spectroscopic parameters for the two observed rotamers of phenylephrine obtained from CP-FTMW spectra}
        \label{chp6:tb2} % should go after \caption
        \setlength{\tabcolsep}{0pt}
        \sisetup{table-align-text-post=false,detect-all=true}
        \begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}} ll
          S[table-format=4.5(3)e-1,group-digits=false,table-align-exponent=false]
          S[table-format=4.5(3),group-digits=false] @{} }
            \toprule
            &   & {Rotamer $I$}  & {Rotamer $II$}   \\
            \midrule
            \multirow{3}{*}{LA-CP-FMTW} &$A$ & 2094.0113(113) & 1908.0283(405)\\                           &$B$          & 468.35153(101) & 452.29425(85) \\                                     
            &$C$         & 411.50542(117) & 412.59360(74) \\
            &$\Delta_{J}$& -1.53(53)d-5 & {-}  \\
            &$\Delta_{K}$& 2.59(38)d-2 & {-}  \\
            &$N$         & 59 & 36 \\
            &$\sigma$    & 29  & 29  \\
            \midrule
            \multirow{3}{*}{LA-MB-FTMW} &$A$           & 2094.10270(107) & 1908.1532(188)\\
            &$B$           & 468.35339(8)    & 452.29545(11)\\
            &$C$           & 411.50313(8)    & 412.59709(10)\\
            &$\chi_{aa}$   & 2.7267(218)     & 2,6753(129)\\
            &$\chi_{bb}$   & -2.6047(159)    & -3,9435(134)\\
            &$\chi_{cc}$   & -0.1219(159)    & 1,2681(134)\\
            &$N$           & 18                    & 20 \\
            &$\sigma$      & 1.2                   & 1.5 \\
            \midrule
            \multirow{3}{*}{Theoretical}&$A$& 2069    & 1860 \\                                 
            &$B$& 470    & 455 \\                                 
            &$C$& 413    & 417 \\
            &$\chi_{aa}$& 2.76 & 2.73\\
            &$\chi_{bb}$& -2.40 & -319\\
            &$\chi_{cc}$& -0.36 &0.46\\
            \bottomrule
        \end{tabular*}
    \begin{tablenotes}\scriptsize\smallskip\raggedright
            \item to be concluded
        \end{tablenotes}
    \end{threeparttable}
\end{table*}
\end{document}
6
  • So, using siunitx, when you use S for alignment, you're actually creating something similar to a siunitx environment within the column?
    – Strelok
    Feb 12, 2020 at 10:02
  • And have you realized how far off are the powers of 10 relative to the rest of the number?
    – Strelok
    Feb 12, 2020 at 10:04
  • 2
    @Strelok the S type column is containing the number parser and additionally gives you alignment at the decimal places. It is even possible to turn off alignment and only use it as a number parser using the table-parse-only option.
    – Skillmon
    Feb 12, 2020 at 10:05
  • 1
    @Strelok yes, they appear far off, because they are aligned under each other as well, just like the decimal markers.
    – Skillmon
    Feb 12, 2020 at 10:06
  • 2
    @Strelok see the edit, this one doesn't align the exponents, such that they are directly following the number, it uses the table-align-exponent=false switch.
    – Skillmon
    Feb 12, 2020 at 10:09
2

Here's an answer that's very similar to @Skillmon's solution -- in particular, I've removed all \num wrappers -- with the following exceptions:

  • Omitted \captionsetup{font=scriptsize}

  • Omitted the meaningless position specifier [!htb] after \begin{threeparttable}

  • Added the options separate-uncertainty=true and tight-spacing=true to the \sisetup instruction

  • Used S[table-format=4.5(5)e-2] for the first data column and S[table-format=4.5(5)] for the second

    Aside: If you don't like employing the separate-uncertainty=true option, I suggest you also change the preceding statements to S[table-format=4.5(3)e-2] and S[table-format=4.5(2)], respectively.

  • Changed second column to automatic math mode; no more need for the multitude of $ symbols in that column

  • Dropped the \multirow wrappers for the entries in the first column

enter image description here

\documentclass[a4paper]{article}
\usepackage{siunitx,caption,booktabs}
\usepackage[flushleft]{threeparttable}

\begin{document}

\begin{table}
\setlength{\tabcolsep}{0pt}
\begin{threeparttable}

        %\captionsetup{font=scriptsize} % why??
        \caption{Experimental spectroscopic parameters for the two 
        observed rotamers of phenylephrine obtained from CP-FTMW spectra}
        \label{chp6:tb2} 
        
        \sisetup{separate-uncertainty=true,
                 tight-spacing,
                 group-digits=false}

        \begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}}
            l 
            >{$}l<{$} % left-aligned & automatic math mode
            S[table-format=4.5(5)e-2]
            S[table-format=4.5(5)] }
            \toprule
            & & {Rotamer $I$}  & {Rotamer $II$}   \\
            \midrule
            LA-CP-FMTW 
            &A         & 2094.0113(113)  & 1908.0283(405)\\                           
            &B         &  468.35153(101) &  452.29425(85)\\
            &C         &  411.50542(117) &  412.59360(74)\\
            &\Delta_{J}& -1.53(53)d-5 & {--}  \\
            &\Delta_{K}&  2.59(38)d-2 & {--}  \\
            &N         & 59  & 36 \\
            &\sigma    & 29  & 29 \\
            \midrule
            LA-MB-FTMW
            &A           & 2094.10270(107)  & 1908.1532(188)\\
            &B           &  468.35339(8)    &  452.29545(11)\\
            &C           &  411.50313(8)    &  412.59709(10)\\
            &\chi_{aa}   &    2.7267(218)   &    2,6753(129)\\
            &\chi_{bb}   &   -2.6047(159)   &   -3,9435(134)\\
            &\chi_{cc}   &   -0.1219(159)   &    1,2681(134)\\
            &N           &   18             &   20  \\
            &\sigma      &    1.2           &    1.5 \\
            \midrule
            Theoretical\tnote{*}
            &A        & 2069    & 1860 \\
            &B        &  470    &  455 \\
            &C        &  413    &  417 \\
            &\chi_{aa}&    2.76 &    2.73\\
            &\chi_{bb}&   -2.40 & -319   \\
            &\chi_{cc}&   -0.36 &    0.46\\
            \bottomrule
        \end{tabular*}
        
        \footnotesize\smallskip\raggedright
        \begin{tablenotes}
            \item[*] to be concluded
        \end{tablenotes}
\end{threeparttable}
\end{table}
\end{document} 

You must log in to answer this question.

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