This is a follow up to question siunitx: specifying custom command as input-symbol . The idea is that (
,)
and -
are wrapped into \llap
or \rlap
so that they do not take any space when a table is set via siunitx
.
The problem is that it does not work when I have (-
in one column: because it is substituted with \llap{(}\llap{-}
, causing the left bracket and the minus to be overlapping. Obviously this would need to become \llap{(-}
. But I don't know how to achieve this in the current framework developed by David Carlisle as shown in the MWE below.
\documentclass[11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenx}
\usepackage{lmodern}
\usepackage[euler-digits]{eulervm}
\newcommand{\sym}[1]{\rlap{#1}}
\usepackage{siunitx}
\sisetup{
detect-mode,
group-digits = false,
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}
\begin{document}
\begin{table}\centering
\textsymbols
\begin{tabular}{l*{3}{S[table-format=1.2,table-column-width=20mm]}}
Variable 1 & 1.85\sym{***} & 0.92\sym{***} & 1.11\sym{***} \\
& (-0.34) & (0.24) & (0.14) \\
Variable 2 & 0.07\sym{***} & 0.07\sym{***} & 0.07\sym{***} \\
& (-0.01) & (0.02) & (0.01) \\
\end{tabular}
\end{table}
\end{document}
Best Answer
You can make
(
lookahead and handle a following-
(again with corrected code and image)