我有一张包含各种值的表格。我想让它们在小数点上对齐并四舍五入为 4 位有效数字。除了负数外,这似乎工作正常。
% !TEX TS-program = XeLaTeX
\documentclass[letterpaper, 12pt]{report}
\usepackage{caption}
\usepackage{amsmath} % American Mathmatical Societey
\usepackage{booktabs} % for nice tables
\usepackage{pslatex} %Times font
% *****************************************************************
% siunitx
% *****************************************************************
\usepackage{siunitx}
\sisetup{
detect-mode,
tight-spacing = true,
group-digits = false ,
input-signs = ,
input-symbols = ( ) [ ] - + *,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-post = false,
bracket-negative-numbers,
round-mode = places,
round-precision = 3,
negative-color = red
}
\begin{document}
\begin{table}[p]
\centering
\caption{Results of Regression Analysis: \\ (Dependent Variable = Dropout Rate)}
\label{tab:regress}
\begin{tabular}{@{}lSSSSSS}
\toprule
& & {Robust} & & & & \\
Variable & {Coeff} & {Std Err} & {t} & {P>t} & \multicolumn{2} {c}{[95\% Conf. Interval]} \\
\midrule
Per Pupil K & -0.174 & 0.026841 & -6.48 & 0 & -0.2265755 & -0.1213346 \\ \addlinespace
North South & & & & & & \\
South & -0.037 & 0.123 & -0.31 & 0.76 & -0.279& 0.203 \\
Alaska Hawaii & 2.138685 & 1.364939 & 1.57 & 0.117 & -0.5372051 & 4.814576 \\ \addlinespace
Locale & & & & & & \\
Large City & 2.196757 & 0.6684642 & 3.29 & 0.001 & 0.8862684 & 3.507246 \\
Mid Size City & 1.424357 & 0.2531437 & 5.63 & 0 & 0.9280816 & 1.920631 \\
Urban Fringe of Lg. & -0.1878159 & 0.1173635 & -1.6 & 0.11 & -0.4179009 & 0.0422691 \\
Urban Fringe Of Med. & 0.0142511 & 0.1131159 & 0.13 & 0.9 & -0.2075067 & -0.4179009 \\ \midrule
Obs & 4,923 &&&&& \\
$R^2$ & 0.257 &&&&& \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
这里有一个解决方法,并进行了一些改进:您的表格对于标准页面来说太宽了,因此我加载了geometry
更合理的边距,减少了值\tabcolsep
并用 替换了过时的pslatex
,newtxtext,newtxmath
基于TeX Gyre Termes
我还加载了makecell
允许在标准单元格中换行的时间克隆。
\documentclass[letterpaper, 12pt]{report}
\usepackage{geometry}
\usepackage{caption}
\usepackage{amsmath} % American Mathmatical Societey
\usepackage{booktabs} % for nice tables%
%\usepackage{pslatex} %Times font obsolete
\usepackage{newtxtext, newtxmath}
\usepackage{makecell, array}
% *****************************************************************
% siunitx
% *****************************************************************
\usepackage{siunitx}
\sisetup{
detect-mode,
tight-spacing = true,
group-digits = false ,
input-signs =- ,
input-symbols = ( ) [ ] - + *,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-post = false,
bracket-negative-numbers,
round-mode = places,
round-precision = 3,
negative-color = red,
table-space-text-pre = $-$,
table-align-text-pre = false
}
\begin{document}
\begin{table}[p]
\centering\setlength{\tabcolsep}{3.5pt}
\caption{Results of Regression Analysis: \\ (Dependent Variable = Dropout Rate)}
\label{tab:regress}
\begin{tabular}{@{}l*{6}{S}@{}}
\toprule
Variable & {Coeff} & {\makecell{Robust\\Std Err}} & {t} & {P${} >{} $t} & \multicolumn{2} {c}{\makecell{[95\,\% Conf. \\ Interval]}} \\
\midrule
Per Pupil K & -0.174 & 0.026841 & -6.48 & 0 & {$-$} 0.2265755 & {$-$} 0.1213346 \\ \addlinespace
North South & & & & & & \\
South & -0.037 & 0.123 & -0.31 & 0.76 & -0.279& 0.203 \\
Alaska Hawaii & 2.138685 & 1.364939 & 1.57 & 0.117 & {$-$}0.5372051 & 4.814576 \\ \addlinespace
Locale & & & & & & \\
Large City & 2.196757 & 0.6684642 & 3.29 & 0.001 & 0.8862684 & 3.507246 \\
Mid Size City & 1.424357 & 0.2531437 & 5.63 & 0 & 0.9280816 & 1.920631 \\
Urban Fringe of Lg. & {$ - $}0.1878159 & 0.1173635 & -1.6 & 0.11 & {$-$}0.4179009 & 0.0422691 \\
Urban Fringe Of Med. & 0.0142511 & 0.1131159 & 0.13 & 0.9 & {$-$}0.2075067 & {$-$}0.4179009 \\ \midrule
Obs & 4,923 &&&&& \\
$R^2$ & 0.257 &&&&& \\
\bottomrule
\end{tabular}
\end{table}
\end{document}