我有一张表格,其格式如下:
\begin{table}[h!]
\begin{center}
\begin{tabular}[t]{cccc}
\hline
{Combo} & {$|r|>0.5$} & {$n>100$} & {$r^2n$} \\
\hline
{U-V} & 0.558545 & 11640 & 3631.36 \\
{U-R} & 0.567270 & 11632 & 3743.12 \\
{U-I} & 0.579188 & 11626 & 3900.04 \\
{U-J} & 0.536106 & 3709 & 1066 \\
{U-K} & 0.535644 & 3730 & 1070.19 \\
{B-V} & 0.580019 & 11884 & 3998.04 \\
{B-R} & 0.574867 & 11763 & 3887.34 \\
{B-I} & 0.591288 & 11749 & 4107.7 \\
{V-U} & -0.558545 & 11640 & 3631.36 \\
{V-B} & -0.580019 & 11884 & 3998.04 \\
{R-U} & -0.567270 & 11632 & 3743.12 \\
{R-B} & -0.574867 & 11763 & 3887.34 \\
{R-W2} & -0.535443 & 4022 & 1153.1 \\
{I-U} & -0.579188 & 11626 & 3900.04 \\
{I-B} & -0.591288 & 11749 & 4107.7 \\
{I-W2} & -0.574056 & 4020 & 1324.75 \\
{J-U} & -0.536106 & 3709 & 1066 \\
{J-W2} & -0.577232 & 1943 & 647.401 \\
{K-U} & -0.535644 & 3730 & 1070.19 \\
{K-W1} & -0.512554 & 1938 & 509.136 \\
{K-W2} & -0.591156 & 1960 & 684.953 \\
{W1-K} & 0.512554 & 1938 & 509.136 \\
{W2-R} & 0.535443 & 4022 & 1153.1 \\
{W2-I} & 0.574056 & 4020 & 1324.75 \\
{W2-J} & 0.577232 & 1943 & 647.401 \\
{W2-K} & 0.591156 & 1960 & 684.953 \\
\hline
\end{tabular}
\caption[Best photometric colours from the MgII dataset]{Photometric colours with highest r-value from the MgII dataset.}
\label{table:MgII_colours}
\end{center}
\end{table}
生产:
但我需要数字列按小数点对齐。从这个问题我尝试将其格式化为
\begin{table}
\centering
\addtolength{\tabcolsep}{-0.3pt}
\begin{tabular}{
@{}
l
S[table-format=1.2]
S[table-format=1.2]
S[table-format=2.3]
@{}
}
\hline
{Combo} & {$|r|>0.5$} & {$n>100$} & {$r^2n$} \\
\hline
{U-V} & 0.558545 & 11640 & 3631.36 \\
{U-R} & 0.567270 & 11632 & 3743.12 \\
{U-I} & 0.579188 & 11626 & 3900.04 \\
{U-J} & 0.536106 & 3709 & 1066 \\
{U-K} & 0.535644 & 3730 & 1070.19 \\
{B-V} & 0.580019 & 11884 & 3998.04 \\
{B-R} & 0.574867 & 11763 & 3887.34 \\
{B-I} & 0.591288 & 11749 & 4107.7 \\
{V-U} & -0.558545 & 11640 & 3631.36 \\
{V-B} & -0.580019 & 11884 & 3998.04 \\
{R-U} & -0.567270 & 11632 & 3743.12 \\
{R-B} & -0.574867 & 11763 & 3887.34 \\
{R-W2} & -0.535443 & 4022 & 1153.1 \\
{I-U} & -0.579188 & 11626 & 3900.04 \\
{I-B} & -0.591288 & 11749 & 4107.7 \\
{I-W2} & -0.574056 & 4020 & 1324.75 \\
{J-U} & -0.536106 & 3709 & 1066 \\
{J-W2} & -0.577232 & 1943 & 647.401 \\
{K-U} & -0.535644 & 3730 & 1070.19 \\
{K-W1} & -0.512554 & 1938 & 509.136 \\
{K-W2} & -0.591156 & 1960 & 684.953 \\
{W1-K} & 0.512554 & 1938 & 509.136 \\
{W2-R} & 0.535443 & 4022 & 1153.1 \\
{W2-I} & 0.574056 & 4020 & 1324.75 \\
{W2-J} & 0.577232 & 1943 & 647.401 \\
{W2-K} & 0.591156 & 1960 & 684.953 \\
\hline
\end{tabular}
\caption[Best photometric colours from the MgII dataset]{Photometric colours with highest r-value from the MgII dataset.}
\label{table:MgII_colours}
\end{table}
但它却做出了这样的事情:
为什么中间两列被挤压了?我对 LaTex 还不太熟悉,对 也非常陌生siunitx
。另外,有没有什么方法可以避免在文本列条目周围加上括号?当有很多行时,这有点麻烦。
答案1
您只需要在table-format
s 中设置适当的值即可。在您的例子中,您必须担心小数点分隔符前后的位数,以及第二列中的符号的存在。
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\addtolength{\tabcolsep}{-0.3pt}
\sisetup{group-digits=integer}
\begin{tabular}{
@{}
l
S[table-format=+1.6]
S[table-format=5.0]
S[table-format=4.3]
@{}
}
\toprule
Combo & {$|r|>0.5$} & {$n>100$} & {$r^2n$} \\
\midrule
U-V & 0.558545 & 11640 & 3631.36 \\
U-R & 0.567270 & 11632 & 3743.12 \\
U-I & 0.579188 & 11626 & 3900.04 \\
U-J & 0.536106 & 3709 & 1066 \\
U-K & 0.535644 & 3730 & 1070.19 \\
B-V & 0.580019 & 11884 & 3998.04 \\
B-R & 0.574867 & 11763 & 3887.34 \\
B-I & 0.591288 & 11749 & 4107.7 \\
V-U & -0.558545 & 11640 & 3631.36 \\
V-B & -0.580019 & 11884 & 3998.04 \\
R-U & -0.567270 & 11632 & 3743.12 \\
R-B & -0.574867 & 11763 & 3887.34 \\
R-W2 & -0.535443 & 4022 & 1153.1 \\
I-U & -0.579188 & 11626 & 3900.04 \\
I-B & -0.591288 & 11749 & 4107.7 \\
I-W2 & -0.574056 & 4020 & 1324.75 \\
J-U & -0.536106 & 3709 & 1066 \\
J-W2 & -0.577232 & 1943 & 647.401 \\
K-U & -0.535644 & 3730 & 1070.19 \\
K-W1 & -0.512554 & 1938 & 509.136 \\
K-W2 & -0.591156 & 1960 & 684.953 \\
W1-K & 0.512554 & 1938 & 509.136 \\
W2-R & 0.535443 & 4022 & 1153.1 \\
W2-I & 0.574056 & 4020 & 1324.75 \\
W2-J & 0.577232 & 1943 & 647.401 \\
W2-K & 0.591156 & 1960 & 684.953 \\
\bottomrule
\end{tabular}
\caption[Best photometric colours from the MgII dataset]{Photometric colours with highest r-value from the MgII dataset.}
\label{table:MgII_colours}
\end{table}
\end{document}