Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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}
share|improve this answer
    
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 tex.stackexchange.com/questions/167266/…. 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 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 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 at 19:40
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.