我剛剛發現siunitx
,這似乎可以對錶格執行我想要的操作,即將列居中但保持數字小數點對齊。我發現它不適用於一列整數(例如 99、9、99、99)。這些數字彼此正確對齊,但在列內未正確居中,而是向其應在的位置左側移動了一兩個位置。我使用的siunitx
選項沒有更改,只是簡單的 {S} 作為列類型。它對於帶有小數點的數字列效果很好,但它會導致整數列錯誤。
答案1
您可以使用該table-format
選項來指定為表中數字的每個部分留出多少空間。如果您的整數最多為 3 位,則可以為table-format=3
3 位整數留出空間,並且不能保留小數。
如註釋中所述,也可以透過在使用時將選項傳遞給列定義來按列設定此選項。
這是一個例子:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{table}
\sisetup{
table-format = 2,
}
\begin{tabular}{SSS}
A & B & C \\
15 & 3 & 2 \\
20 & 2 & 19 \\
25 & 24 & 4 \\
\end{tabular}
\end{table}
\begin{table}
\begin{tabular}{
S[table-format=2.3] % with space for integers and decimals
S[table-format=2] % with space for integers only
S % as the default
}
A & B & C \\
15 & 3 & 2 \\
20 & 2 & 19 \\
25 & 24 & 4 \\
\end{tabular}
\end{table}
\end{document}
對齊整數的外觀如下: