3

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}

enter image description here

Jörg
  • 7,653

1 Answers1

4

You can make ( lookahead and handle a following -

(again with corrected code and image)

enter image description here

\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 }

\makeatletter

\def\xxxl#1{%
\bgroup\uccode`\~\expandafter`\string#1%
\uppercase{\egroup\edef~##1{##1\edef\noexpand\thisxxx{\string#1}\futurelet\noexpand\tmp\noexpand\zzz}}%
\mathcode\expandafter`\string#1"8000 }


\def\zzzx#1#2{\def\tmp{#2}%
\ifx\tmp\zzzm
\text{\llap{\thisxxx$\mathchar"2200$}}%
\else
#1{#2}%
\fi}


\def\zzzm{-}
\def\zzz{\ifx\tmp\ensuremath
           \expandafter\zzzx
          \else
\text{\llap{\thisxxx}}%
          \fi}

%\noexpand\@ifnextchar\noexpand-\noexpand\xxxlm{\noexpand\text{\noexpand\llap{\string#1}
\makeatother

\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}
David Carlisle
  • 757,742
  • Brilliant, that works! Two points: Could you elaborate a bit on what the code does? I get lost from futureletonwards. And within my framework I don't use the mathminus because that's the one from Eulermath. I used textendash here for simplification, but normally I use textminus from textcomp (works fine with your solution). – Jörg Nov 19 '12 at 17:23
  • maybe later :-) – David Carlisle Nov 19 '12 at 17:28
  • @DavidCarlisle I know you only said 'maybe' but you must admit that it is 'later'... I was trying to understand your code in relation to http://tex.stackexchange.com/questions/167266/minionpro-siunitx-and-some-character-substitution-bad-mathchar-32768. I can't get your solution here to work there anyway, but I was initially interested in why you'd used a different solution for left and right (whereas the OP there is trying a symmetrical solution). – cfr Mar 23 '14 at 19:07
  • @cfr the question here (as far as I recall thinking it about at the time) was specifically about (- so I only handled that case not ) – David Carlisle Mar 23 '14 at 19:20
  • Ah, OK. That actually makes a lot more sense of what you were doing. [Not that I understand it but I can sort of get the general idea.] Thanks. – cfr Mar 23 '14 at 19:40
  • @cfr I just had look at the other qn but I don't have the font package (nor the incentive to install it:-) so I can't see why it generates the mathchar error. – David Carlisle Mar 23 '14 at 19:44
  • @cfr I've closed the question you linked because it was essentially a duplicate. The trickery above does not work with - when amsmath is loaded which MinionPro does by default. David already provided a solution for that. – Jörg Mar 28 '14 at 10:31