siunitx error: Invalid numerical input

You forgot to add option input-symbols = {( )}. With adding it and cleaning a bit of your code, I obtain:

enter image description here

MWE:

\documentclass{article}

\usepackage{siunitx}
\usepackage{pdflscape}
\usepackage{booktabs}
\newcommand\dsh{\multicolumn{3}{c@{\hspace{2em}}}{--}}
\newcommand\mcc[1]{\multicolumn{3}{@{} c @{\hspace{1em}}}{$#1$}}

\begin{document}
\begin{landscape}
\begin{table}
% \centering 
\sisetup{table-format=1.3,      % <---
         input-symbols = {( )}} % <===
\begin{tabular}{
         >{$}l<{$}
        *{3}{S @{\hspace{0.5em}}
         >{(}S[table-space-text-pre={(}]
        @{,\,}
             S[table-space-text-post={)}]<{)}@{\hspace{2em}} 
                }
        S @{\hspace{0.5em}}
        >{{(}}
        S[table-space-text-pre={(}]
       @{,\,}
        S[table-space-text-post={)}]<{)}
                }
    \toprule
            & \mcc{\mathit{Exp}(\lambda)}   & \mcc{G(2,\lambda)}
            & \mcc{G(3,\lambda)}            & \mcc{N^+(\mu,\omega^2)} \\
    \midrule
\alpha_0    & 4.239 & 4.150 & 4.330   & 4.315 & 4.225 & 4.404
            & 4.371 & 4.281 & 4.459   & 4.273 & 4.183 & 4.365   \cr
\alpha_1    & 0.024 & 0.024 & 0.025   & 0.024 & 0.024 & 0.025
            & 0.024 & 0.024 & 0.025   & 0.024 & 0.024 & 0.025\cr
\beta_1     & 0.054 & 0.049 & 0.060   & 0.051 & 0.045 & 0.056
            & 0.049 & 0.043 & 0.054   & 0.051 & 0.046 & 0.057\cr
\beta_2     & 0.755 & 0.749 & 0.761   & 0.761 & 0.755 & 0.767
            & 0.765 & 0.758 & 0.771   & 0.761 & 0.755 & 0.767\cr
\beta_3     & 0.109 & 0.102 & 0.116   & 0.106 & 0.099 & 0.113
            & 0.105 & 0.098 & 0.112   & 0.106 & 0.099 & 0.113\cr
\sigma^2    & 0.032 & 0.031 & 0.033   & 0.031 & 0.030 & 0.032
            & 0.030 & 0.030 & 0.031   & 0.031 & 0.030 & 0.032\cr
\lambda     & 1.426 & 1.352 & 1.502   & 2.468 & 2.356 & 2.588
            & 3.383 & 3.240 & 3.531   & \dsh\cr
\mu         & \dsh  & \dsh  & \dsh    & 0.286 & 0.243 & 0.324\cr
\omega^2    & \dsh  & \dsh  & \dsh    & 0.440 & 0.397 & 0.485\cr
\omega^2    & \multicolumn{3}{c@{\hspace{2em}}}{--}
            & \multicolumn{3}{c@{\hspace{2.5em}}}{--}
            & \multicolumn{3}{c@{\hspace{2.5em}}}{--}
                                      & 0.440 & 0.397 & 0.485\cr
\mathrm{DIC}& \mcc{-9687.5} & \mcc{-10274.1}  & \mcc{-10592.1}
            & \mcc{-10173.7}\cr
    \bottomrule
\end{tabular}
\end{table}
\end{landscape}
\end{document}

edit: corrected column specification.


Your code doesn't seem to require the siunitx package and its S column type. The basic c column type would appear to perform just as well.

Another suggestion: use an array environment rather than a tabular environment; this change will save you from having to type lots of $ symbols.

In addition to replacing S with c in the following example, I cleaned up and simplified your code a bit.

enter image description here

\documentclass{article}
\usepackage{array,amsmath,pdflscape,booktabs}

\begin{document}
\begin{landscape}
\begin{table}
\centering
\setlength\arraycolsep{1em}
$\begin{array}{@{}
        l 
        *{4}{ c 
              @{\hspace{1em}}
              >{(}c
              @{,\,}
              c<{)} }
        @{}}

    \toprule

    & \multicolumn{3}{c}{\exp(\lambda)} 
    & \multicolumn{3}{c}{G(2,\lambda)} 
    & \multicolumn{3}{c}{G(3,\lambda)} 
    & \multicolumn{3}{c@{}}{N^+(\mu,\omega^2)} \\

    \midrule

    \alpha_0 & 4.239 & 4.150 & 4.330   & 4.315 & 4.225 & 4.404   
       & 4.371 & 4.281 & 4.459   & 4.273 & 4.183 & 4.365\\
    \alpha_1 & 0.024 & 0.024 & 0.025   & 0.024 & 0.024 & 0.025   
       & 0.024 & 0.024 & 0.025   & 0.024 & 0.024 & 0.025\\
    \beta_1  & 0.054 & 0.049 & 0.060   & 0.051 & 0.045 & 0.056   
       & 0.049 & 0.043 & 0.054   & 0.051 & 0.046 & 0.057\\
    \beta_2  & 0.755 & 0.749 & 0.761   & 0.761 & 0.755 & 0.767   
       & 0.765 & 0.758 & 0.771   & 0.761 & 0.755 & 0.767\\
    \beta_3  & 0.109 & 0.102 & 0.116   & 0.106 & 0.099 & 0.113   
       & 0.105 & 0.098 & 0.112   & 0.106 & 0.099 & 0.113\\
    \sigma^2 & 0.032 & 0.031 & 0.033   & 0.031 & 0.030 & 0.032   
       & 0.030 & 0.030 & 0.031   & 0.031 & 0.030 & 0.032\\
    \lambda  & 1.426 & 1.352 & 1.502   & 2.468 & 2.356 & 2.588   
       & 3.383 & 3.240 & 3.531   & \multicolumn{3}{c@{}}{\text{--}}\\

    \mu 
    & \multicolumn{3}{c}{\text{--}} 
    & \multicolumn{3}{c}{\text{--}} 
    & \multicolumn{3}{c}{\text{--}}    
    & 0.286 & 0.243 & 0.324\\
    \omega^2 
    & \multicolumn{3}{c}{\text{--}} 
    & \multicolumn{3}{c}{\text{--}} 
    & \multicolumn{3}{c}{\text{--}}   
    & 0.440 & 0.397 & 0.485\\
    \mathrm{DIC}
    & \multicolumn{3}{c}{-9687.5} 
    & \multicolumn{3}{c}{-10274.1} 
    & \multicolumn{3}{c}{-10592.1} 
    & \multicolumn{3}{c@{}}{-10173.7}\\

    \bottomrule
\end{array}$
\end{table}
\end{landscape}
\end{document}

Addendum: If you do need to use the S column type, all you'd have to change in the code above is (a) load the siunitx package and (b) replace

$\begin{array}{@{}
        l 
        *{4}{ c 
              @{\hspace{1em}}
              >{(}c
              @{,\,}
              c<{)} }
        @{}}

with

\sisetup{input-symbols = {()}, % inform siunitx that "(" and ")" have no special meaning
         table-format=1.3}
$\begin{array}{@{}
        l 
        *{4}{ S 
              @{\hspace{1em}}
              >{(}S
              @{,\,}
              S<{)} }
        @{}}

You correctly surmised that the opening parenthesis is always treated as marking the start of the uncertainty. This is necessary for siunitx to be able to reliably parse numbers. The option table-space-text-pre does not change this; it only adds the width of its value (( in this case) to the column, the actual token (() is not treated any differently because of this.

You can still achieve your goal without redefining the uncertainty input by hiding the parentheses from the parser. This can be done by putting them inside a group (between { and }). It looks like you already tried this in >{{(}}, but the error message tells you that this group is not there any more when the siunitx parser reads the parenthesis. How can this be?

When TeX consumes the argument of a macro, it strips it of one layer of braces (if present). This means that sometimes, depending on the implementation of the macros you are using, some of the braces you type disappear before they reach the part of the machine they were meant for.

There are two ways of dealing with this.

  • You could add more braces. In your case, one additional layer is enough: >{{{(}}}
  • You can hide your braces from TeX by putting them inside a macro. Define a macro \newcommand*\foo{{(}} and use it like >{\foo}. Now, when this argument is handed through the different macros implementing the table, \foo is still unexpanded. It only gets expanded once the siunitx parser tries to make sense of its input and then it finds {(}, as desired. In general, this approach is much safer and easier than the first one since you don't have to first find out how many layers of braces you need and your code does not break when this number changes.

As to why this does not occur in older versions of siunitx I can only guess. To me, it looks like either a bug in the old versions or a new feature in the new ones. (Being able to add parts of the number before parsing using > and < is definitely a feature, I would say.)

Tags:

Tables

Siunitx