![如何使用 siunitx 將表格信賴區間列印為 [x, y]?](https://rvso.com/image/327772/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20siunitx%20%E5%B0%87%E8%A1%A8%E6%A0%BC%E4%BF%A1%E8%B3%B4%E5%8D%80%E9%96%93%E5%88%97%E5%8D%B0%E7%82%BA%20%5Bx%2C%20y%5D%EF%BC%9F.png)
[x, y]
在 S 列中列印置信區間的建議方法是什麼siunitx
?目前我有一個兩個S列的解:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\begin{tabular}{cS[table-format = 1.1]
S[table-format = -1.2, table-space-text-pre=[ ]@{}
S[table-format = -1.2, table-space-text-post=[, table-space-text-pre=[ ]
}
A & B & \multicolumn{2}{c}{CI} \\
Values & 2.3 & {[}1.23{,} & 1.23{]} \\
Values & 2.3 & {[}-3.42{,} & -2.43{]} \\
Values & 2.3 & {[}4.12{,} & 7.33{]} \\
Values & 2.3 & {[}-1.03{,} & -9.11{]} \\
\end{tabular}
\end{table}
\end{document}
有更容易的siunitx
方法嗎?
答案1
您可以利用table-space-text-pre
和table-space-text-post
為方括號騰出空間。要在列之前和之後插入括號,請使用>{...}
and<{...}
語法。為了避免每行最後一個方括號之前的間距錯誤,您必須使用 TeX 原語\cr
而不是 og\\
來終止行,如 7.13 節所述。siunitx
手動的。
要將列標題居中,B
您只需將其放入一個群組中,例如{B}
。
\documentclass[border=10pt]{standalone}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{
c
S[table-format = 1.1]
>{{[}} % Add square bracket before column
S[table-format = -1.2,table-space-text-pre={[}]
@{,\,} % Add comma and thin-space between the columns
S[table-format = -1.2,table-space-text-post={]}]
<{{]}} % Add square bracket after column
}
A & {B} & \multicolumn{2}{c}{CI} \cr
Values & 2.3 & 1.23 & 1.23 \cr
Values & 2.3 & -3.42 & -2.43 \cr
Values & 2.3 & 4.12 & 7.33 \cr
Values & 2.3 & -1.03 & -9.11 \cr
\end{tabular}
\end{document}
答案2
我嘗試盡量減少輸入次數,因此我將括號[
和]
放入表定義中:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\begin{tabular}{cS[table-format = 1.1]
@{\quad[\,}S[table-format = -1.2]@{,\,}S[table-format = -1.2]@{\,]}
}
A & \multicolumn{1}{c@{\quad\space}}{B} & \multicolumn{2}{c}{CI} \\
Values & 2.3 & 1.23 & 1.23 \\
Values & 2.3 & -3.42 & -2.43 \\
Values & 2.3 & 4.12 & 7.33 \\
Values & 2.3 & -1.03 & -9.11 \\
\end{tabular}
\end{table}
\end{document}
這會產生:
在這裡,我習慣@{...}
在列之間插入材料。注意視線拼湊以到達B
正確的位置。這是必要的,因為\quad
,但它往往表明應該有一個更優雅的解決方案!