# Siunitx digit-grouping inserts comma in decimal part of a three decimal point number in parathese

I am following the answer by dapperdan to get regression results from Stata in Latex (using the command estout) and from there to LyX. Everything works but I wanted to have thousands separated by a comma. For this I changed the sisetup to

\sisetup{
detect-mode,
group-digits            = true,
group-separator         = {,},
input-symbols           = ( ) [ ] - +,
table-align-text-post   = false,
input-signs             = ,
}


Everything looks good except for the number is the parentheses (standard errors). They get an additional comma at the end as can be seen in the pic below:

Clearly, this is not what I want. So something in my setup must be wrong.

A MWE is given here. It is made up of the main part (1) and the tex table fragment (2).

(1) Main tex file

    %% LyX 2.2.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

% *****************************************************************
% Packages for tables
% *****************************************************************

\usepackage{booktabs}% Pretty tables
\usepackage{threeparttablex}% For Notes below table

% *****************************************************************
% siunitx
% *****************************************************************
\newcommand{\sym}[1]{\rlap{#1}} % Thanks to Joseph Wright & David Carlisle

\usepackage{siunitx}
\sisetup{
detect-mode,
group-digits            = true,
group-separator         = {,},
input-symbols           = ( ) [ ] - +,
table-align-text-post   = false,
input-signs             = ,
}

% Character substitution that prints brackets and the minus symbol in text mode. Thanks to David Carlisle
\def\yyy{%
\bgroup\uccode\~\expandafter\string-%
\uppercase{\egroup\edef~{\noexpand\text{\llap{\textendash}\relax}}}%
\mathcode\expandafter\string-"8000 }

\def\xxxl#1{%
\bgroup\uccode\~\expandafter\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\llap{\string#1}}}}%
\mathcode\expandafter\string#1"8000 }

\def\xxxr#1{%
\bgroup\uccode\~\expandafter\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\rlap{\string#1}}}}%
\mathcode\expandafter\string#1"8000 }

\def\textsymbols{\xxxl[\xxxr]\xxxl(\xxxr)\yyy}

% *****************************************************************
% Estout related things
% *****************************************************************
\let\estinput=\input % define a new input command so that we can still flatten the document

\newcommand{\estwide}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular*}
{\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\end{tabular*}
}
}

\newcommand{\estauto}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\end{tabular}
}
}

% Allow line breaks with \\ in specialcells
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}

% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
% The new approach using threeparttables to generate notes that are the exact width of the table.
\newcommand{\Figtext}[1]{%
\begin{tablenotes}[para,flushleft]
\hspace{6pt}
\hangindent=1.75em
#1
\end{tablenotes}
}
\newcommand{\Fignote}[1]{\Figtext{\emph{Note:~}~#1}}
\newcommand{\Figsource}[1]{\Figtext{\emph{Source:~}~#1}}
\newcommand{\Starnote}{\Figtext{* p < 0.1, ** p < 0.05, *** p < 0.01. Standard errors in parentheses.}}% Add significance note with \starnote

\makeatother

\usepackage{babel}
\begin{document}
\begin{table}
\caption{First Table}
\begin{threeparttable}
\estwide{Fra_Table.tex}{3}{S[table-format=2.3]} %% Table Fragment is called here %%
\Fignote{Some Notes}
\Figsource{Own calculations based on data}
% \Starnote
\end{threeparttable}
\end{table}

\end{document}


(2) The table fragment "Fra_Table.tex" called by the newcommand estwide near the end of the above MWE is given below (save in the same folder as you compile the above stuff):

                        &\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         \\
\midrule
2\textsuperscript{nd} stage \\
\midrule
Effect &      -0.100         &      -1.000         &       0.050         \\
&     (2.871)         &     (3.843)         &     (2.311)         \\
Observations        &\multicolumn{1}{S[table-format=5]}{50000}         &\multicolumn{1}{S[table-format=5]}{50000}         &\multicolumn{1}{S[table-format=5]}{50000}         \\

• Welcome to TeX.SE!. Your MWE probably work to you, but for rest of us is not compilable. Please reduce it to minimum (are all definition in preamble is really necessary for your problem?) and insert a table in it and not give it as separated file. – Zarko Feb 16 '17 at 14:32
• @Zarko Thanks for the hints. The large preamble is necessary to correctly format the tex table fragment (Fra_Table.tex) created by the Stata commad estout. I did however incorporate the Ins_Table.tex which I use to input the table into LyX into the MWE. And I clearified what to do with the table fragment. It should be clearer now and hopefully work. – TiredHornet Feb 17 '17 at 13:51

The answer to my question is that I did not specify the group-digits choice key correctly in sisetup. I found the answer in another question: How to omit group separators in the decimal part when using siunitx?

So sisetup should look like this:

\sisetup{
detect-mode,
group-digits = integer,
group-separator = {,},
input-symbols = ( ) [ ] – +,
table-align-text-post = false,
input-signs = ,
}


While this works, I do not quite understand why the group-separator "," only appeared in the decimal part of the numbers in parentheses. Somehow siunitx must think that the closing parenthesis is a digit.

I agree with your (TiredHornet’s) diagnosis that

Somehow siunitx must think that the closing parenthesis is a digit.

I disagree, however, with your statement

The answer to my question is that I did not specify the group-digits choice key correctly in sisetup.

because I don’t think that

group-digits = true


should be regarded “incorrect” usage. There clearly are cases in which you might desire grouping of decimal digits also in tables. It is rather the inclusion of the parentheses as input_symbols that generates the issue:

input-symbols = ( ) [ ] – +,


Here’s my solution to prevent the erroneous insertion of the group-separator before the closing parenthesis:

\sisetup{
detect-all,
round-integer-to-decimal = true,
group-digits             = true,
group-minimum-digits     = 5,
group-separator          = {\kern 1pt},
table-align-text-pre     = false,
table-align-text-post    = false,
input-signs              = + -,
input-symbols            = {*} {**} {***},
input-open-uncertainty   = ,
input-close-uncertainty  = ,
retain-explicit-plus
}


And here’s an example table:

\begin{tabular}
{ @{}
S[table-format=+1.3, table-space-text-pre={**}, table-space-text-post={-**}]
S[table-format=+1.5, table-space-text-pre={**}, table-space-text-post={-**}]
S[table-format=+6.3, table-space-text-pre={**}, table-space-text-post={-**}]
@{}
}
\toprule
{(1)}    &  {(2)}      &  {(3)}          \\
\midrule
-0.100*  &  -0.10001*  &  -123456.444*** \\
(2.871)  &  (2.87123)  &  [+50000.123]   \\
\bottomrule
\end{tabular}
`

which generates the following output: