如何使用 siunitx 將表格信賴區間列印為 [x, y]?

如何使用 siunitx 將表格信賴區間列印為 [x, y]?

[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-pretable-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,但它往往表明應該有一個更優雅的解決方案!

相關內容