![采用 Siunitx 封装的表头左对齐](https://linux22.com/image/415358/%E9%87%87%E7%94%A8%20Siunitx%20%E5%B0%81%E8%A3%85%E7%9A%84%E8%A1%A8%E5%A4%B4%E5%B7%A6%E5%AF%B9%E9%BD%90.png)
我正在尝试使用 Siunitx 包制作一个表格,并使标题中的文本左对齐并从数字开始的位置开始(参见所附屏幕截图中的红线)。有人知道怎么做吗?
梅威瑟:
%:Class
\documentclass[12pt,a4paper]{article}
\usepackage{siunitx}
%:begin
\begin{document}
\begin{table}[htbp]\centering
\caption{Descriptive Statistics}
\begin{tabular}{l|s[table-text-alignment = left]*{4}{|S[table-number-alignment = left]}}
& {N}& {Mean}& {S.D.}& {Min}& {Max}\\
A& 95,703& 0.522& 0.500& 0& 1\\
B& 94,826& 0.062& 0.241& 0& 1\\
C& 94,301& 3.080& 1.435& 1& 6\\
D& 90,049& 0.332& 0.471& 0& 1\\
E& 94,860& 0.065& 0.960& -5.27& 3.49\\
\end{tabular}
\end{table}
\end{document}
答案1
如果我理解得没错的话,这里有一个解决方案,其中有一些美学建议:
\documentclass[12pt,a4paper]{article}
\usepackage{siunitx}
\usepackage{caption}
\captionsetup{skip=6pt, labelfont=sc, textfont=it}
\usepackage{calc}
\newcommand\myShead[1]{\multicolumn{1}{c}{\parbox{\widthof{0.500}}{#1}}}
\begin{document}
\begin{table}[htbp]\centering
\sisetup{table-format = 1.3, table-number-alignment=center, group-separator={,}}
\caption{Descriptive Statistics}
\begin{tabular}{l!{\vrule width1pt}S[table-format =5.0]*{2}{|S}|S[table-format =-1.2]|S}
& \multicolumn{1}{l}{N}& \myShead{Mean}& \myShead{S.D} & \myShead{\phantom{$-\!$}Min}& \myShead{Max}\\
A& 95703 & 0.522& 0.500& 0& 1\\
B& 94826& 0.062& 0.241& 0& 1\\
C& 94301& 3.080& 1.435& 1& 6\\
D& 90049& 0.332& 0.471& 0& 1\\
E& 94860& 0.065& 0.960& -5.27& 3.49\\
\end{tabular}
\end{table}
\end{document}