这是对问题的后续跟进siunitx:指定自定义命令作为输入符号. 其思想是(
,)
和-
被包装到\llap
或中\rlap
,这样当通过设置表格时它们就不会占用任何空间siunitx
。
问题是,当我在一列中有:时它不起作用,(-
因为它被替换为\llap{(}\llap{-}
,导致左括号和减号重叠。显然,这需要变成\llap{(-}
。但我不知道如何在 David Carlisle 开发的当前框架中实现这一点,如下面的 MWE 所示。
\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}
答案1
您可以进行(
前瞻性并处理后续操作-
(再次修正代码和图像)
\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}