我正在关注的答案达普丹在 Latex 中从 Stata 获取回归结果(使用命令 estout),然后从那里获取 LyX。一切正常,但我希望用逗号分隔千位。为此,我将 sisetup 更改为
\sisetup{
detect-mode,
group-digits = true,
group-separator = {,},
input-symbols = ( ) [ ] - +,
table-align-text-post = false,
input-signs = ,
}
除了括号中的数字(标准错误)外,其他一切都很好。它们在末尾有一个额外的逗号,如下图所示:
显然,这不是我想要的。所以我的设置一定有问题。
这里给出了一个 MWE。它由主体部分 (1) 和 tex 表片段 (2) 组成。
(1)主tex文件
%% 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
\addlinespace[.75ex]
\end{tabular*}
}
}
\newcommand{\estauto}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\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)上述 MWE 末尾附近的新命令 estwide 调用的表格片段“Fra_Table.tex”如下所示(保存在与编译上述内容相同的文件夹中):
&\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) \\
\addlinespace
Observations &\multicolumn{1}{S[table-format=5]}{50000} &\multicolumn{1}{S[table-format=5]}{50000} &\multicolumn{1}{S[table-format=5]}{50000} \\
答案1
我的问题的答案是我没有在 sisetup 中正确指定组数字选择键。我在另一个问题中找到了答案:使用 siunitx 时如何省略小数部分的组分隔符?
因此 sisetup 应该是这样的:
\sisetup{
detect-mode,
group-digits = integer,
group-separator = {,},
input-symbols = ( ) [ ] – +,
table-align-text-post = false,
input-signs = ,
}
虽然这有效,但我不太明白为什么组分隔符“,”只出现在括号内数字的小数部分。siunitx 一定认为右括号是一个数字。
答案2
我同意你的(疲倦的黄蜂's) 诊断
siunitx 一定以某种方式认为右括号是一个数字。
但我不同意你的说法
我的问题的答案是我没有在 sisetup 中正确指定组数字选择键。
因为我不认为
group-digits = true
应被视为“不正确”的用法。在某些情况下,您可能也希望在表格中对十进制数字进行分组。相反,括号的包含会input_symbols
产生问题:
input-symbols = ( ) [ ] – +,
group-separator
下面是我的解决方案,以防止在右括号前错误插入:
\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
}
以下是一个示例表:
\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}
生成以下输出: