6

In the following minimal code, when I replace the l columns by S I get an error message saying

invalid-number!! Invalid numerical input '(4.36)'.!!
See the siunitx documentation for further information.!!

It goes on. It is important that I put the numbers in the third and fifth columns in parenthesis.

\documentclass{article}
\usepackage{booktabs}
\usepackage{ctable}
\usepackage{siunitx}
\usepackage{multirow}

\begin{document}
\ctable[
     caption = {caption here},
     label = {tab:tab1},
     pos = {!ht},
     center
] {@{}lS@{\enskip}>{(}l<{)}S@{\enskip}>{(}l<{)}}{
    \tnote[$\dagger$]{footnote here}
}{ \FL
\multirow{2}{*}{var} & \multicolumn{4}{c}{Title here} \\
\cmidrule{2-5}
    & \multicolumn{2}{c}{[AA]} & \multicolumn{2}{c}{[BB]} \ML       
$var_{12}$ & 1.37 & 4.36 & 1.50 & 8.91  \\
$var_{13}$ & 1.73 & 8.43 & 1.84 & 10.88 
\LL}
\end{document}
  • try parse-numbers=false, numbers in (...) need to have a special format with siunitx as in 1.23(45), (4.36) does not follow this rule, thus the error. – daleif Apr 9 '14 at 9:35
3

There are two things we should be careful about.

  1. parenthesis are used to indicate the uncertainty through the table-figures-uncertainty macro
  2. We can use table-parse-only to get the parsing only feature.

For item 1 above, we can hide ( and ) from siunitx by using braces → {(} and {)} so that they are not meant to indicate the uncertainty. table-parse-only gives correct spacing.

Code:

\documentclass{article}
\usepackage{booktabs}
\usepackage{ctable}
\usepackage{siunitx}
\usepackage{multirow}
%\sisetup{detect-weight=true,table-space-text-pre={(},table-space-text-post={)}}

\begin{document}
\ctable[
     caption = {caption here},
     label = {tab:tab1},
     pos = {!ht},
     center
] {@{}lS@{\enskip}>{{(}}S[table-parse-only]<{{)}}S@{\enskip}>{{(}}S[table-parse-only]<{{)}}}{
    \tnote[$\dagger$]{footnote here}
}{ \FL
\multirow{2}{*}{var} & \multicolumn{4}{c}{Title here} \\
\cmidrule{2-5}
    & \multicolumn{2}{c}{[AA]} & \multicolumn{2}{c}{[BB]} \ML
$var_{12}$ & 1.37 & 4.36 & 1.50 & 8.91  \\
$var_{13}$ & 1.73 & 8.43 & 1.84 & 10.88
\LL}
\end{document}

enter image description here

  • Just a side question, if I have another column beneath such as $var_4$ & \multicolumn{2}{}{23.568} & \multicolumn{2}{}{3.988} the S column does not recognize the last two cell entries as numbers. Is there a way to go about this? – Duna Apr 9 '14 at 9:52
  • @Duna When you use \multicolumn things are over ridden. – user11232 Apr 9 '14 at 13:43
5

Instead of providing the option table-parse-only to the siunitx package, you could also provide the -- in my opinion less intrusive -- option input-symbols = (). Doing so tells siunitx to treat the symbols ( and ) as ordinary inputs, i.e., not to assign any special meaning to them (such as denoting uncertainty...).

Two nice features of this approach are (i) you needn't do anything special in the header information of the tabular environment in order to enter the parentheses in the body of the table and (ii) the ability of the siunitx package to align numbers on their decimal points (and to perform any other parsing tasks) is not affected.

enter image description here

\documentclass{article}
\usepackage{booktabs,siunitx}
\sisetup{input-symbols = ()} % "(" and ")" are ordinary inputs
\begin{document}
\begin{table}[ht!]
\caption{caption here} \label{tab:tab1}
\centering
\begin{tabular}{@{}lSSSS@{}}
\toprule
& \multicolumn{4}{c}{Title here} \\
\cmidrule{2-5}
& \multicolumn{2}{c}{[AA]} & \multicolumn{2}{c@{}}{[BB]} \\
\midrule
$var_{12}$ & 1.37 & (4.36) & 1.50 &  (8.91)\\
$var_{13}$ & 1.73 & (8.43) & 1.84 & (10.88)\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
  • This is a very nice idea! But while the numbers in parenthesis are aligned correctly, rounding seems to be ignored. i.e. setting round-precision=1 is correctly applied to columns 2 and 4 but not columns 3 and 5 (which keep their original number of decimals places). Do you know why? – Donna Aug 22 '16 at 4:16
  • 1
    @Donna - (By the way, I assume you also set the option round-mode=places.) The package's user guide says, on page 22, that "No rounding will take place if the number contains an uncertainty component". Uncertainty components can be stated, inter alia, as numbers in parentheses. This working assumption appears to apply in columns 3 and 5 even though the option input-symbols = () has been set. You may want contact the package's maintainer -- his email address is given at the bottom of page 1 of the package's user guide -- and raise your question directly with him. – Mico Aug 22 '16 at 5:31
  • Yes I also set round-mode=places. But I also recently wanted to include numbers in parens to indicate a percentage, and ran into similar issues. I found a work-around using round from the FP package : \FPeval{\x}{round(4.36:1)}{(}\x) (no idea why why the first paren needs to be enclosed in {}. ) – Donna Aug 22 '16 at 14:38
1

As a comment to @Donna's comment in @Mico's post (no rep yet...), you can place the parens in curly braces, and rounding will still occur.

\documentclass{article}
\usepackage{booktabs,siunitx}
\sisetup{input-symbols = ()} % "(" and ")" are ordinary inputs
\begin{document}
\begin{table}[ht!]
\caption{caption here} \label{tab:tab1}
\centering
\begin{tabular}{@{}lSSSS@{}}
\toprule
& \multicolumn{4}{c}{Title here} \\
\cmidrule{2-5}
& \multicolumn{2}{c}{[AA]} & \multicolumn{2}{c@{}}{[BB]} \\
\midrule
$var_{12}$ & 1.3723 & {(}4.3646{)} & 1.5045 &  {(}8.9111{)}\\
$var_{13}$ & 1.7343 & {(}8.4365{)} & 1.8445 & {(}10.8888{)}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

  • Any idea how to avoid the whitespace in front of the number in parantheses and the negative side effects of table-parse-only? – hannes101 Feb 23 '18 at 9:53

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.