將數字與括號對齊時出現問題

將數字與括號對齊時出現問題

英語不是我的母語,但我會盡力以最好的方式解釋我的問題。

我的問題是 L 和 T 列之間的額外間距,這顯然是當我以科學模式書寫數字時出現的。有沒有辦法讓這樣的科學數字,將它們對齊逗號,並使列中的間距更正常(更小)?

前言:

\documentclass[12pt,twoside]{report}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[a4paper,width=150mm,top=25mm,bindingoffset=6mm]{geometry}
\usepackage{amsmath}
\sisetup{input-symbols = ()}

表代碼:

\begin{table}[ht]\centering
\caption[caption]{caption}\label{reg_basis1}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\sisetup{table-space-text-post = \sym{***}}

\begin{tabular}{l*{5}{S[table-align-text-post=false]}}
\toprule
\multicolumn{1}{l}{\textbf{}}&\multicolumn{1}{c}{\textbf{L}}&
\multicolumn{1}{c}{\textbf{T}}&\multicolumn{1}{c}{\textbf{n}}&
\multicolumn{1}{c}{\textbf{\(R^{2}\)}}&
\multicolumn{1}{c}{\textbf{Justert $R^{2}$}}\\
\midrule
1997 - 2008 & 0.207 \sym{***} & 3.5\num{1e-4} \sym{***} & {623} & 0.27 & 0.21  \\
            & (0.049)         & (0.8\num{1e-4})         &       &      &       \\
        \addlinespace
2009 - 2015 &&&&&  \\
            &&&&&  \\
        \addlinespace
\bottomrule
\multicolumn{5}{l}{\footnotesize Estimerte standardavvik er gitt i parenteser}\\
\multicolumn{5}{l}{\footnotesize \sym{*} $p<0.05$, \sym{**} $p<0.01$, \sym{***} \  $p<0.001$}\\
\end{tabular}
\end{table}

我希望這裡的人有時間回答我。我嘗試過搜索/谷歌搜索,但沒有找到任何可以用來解決我的問題的具體內容。

答案1

我認為你的主要問題是(圓)括號用於包圍您的數字,因為它們也用作命令的自然輸入\num以指示數字的錯誤。這就是為什麼您必須將(圓)括號放入大括號中來保護它們。

(我不會使用您的解決方案並將它們添加到 中input-symbols,因為這可能會導致一些不良的副作用,我尚未對此進行測試。)

然後獲得正確的間距非常簡單,並且已經得到了回答,例如這裡向說明符的選項提供可以在列中找到的“元素”,S例如table-format. (看一下siunitx手冊 v2.6 第 47 頁的表 25)。

看看下面的程式碼,我稍微減少了一些程式碼,以免分散對主表格的注意力。

\documentclass[border=2mm]{standalone}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \sisetup{
            table-align-text-post=false,
        }
    \begin{tabular}{
        l
        S[table-format=1.3,   table-space-text-pre={(},table-space-text-post={\sym{***}}]
        S[table-format=1.1e-1,table-space-text-pre={(},table-space-text-post={\sym{***}}]
        S[table-format=3]
        S[table-format=1.2]
        S[table-format=1.2]
        }
            \toprule
                      & {\textbf{L}}    & {\textbf{T}}   & {\textbf{n}}
                                                               & {\textbf{$R^{2}$}}
                                                                      & {\textbf{Justert $R^{2}$}} \\
            \midrule
        1997 -- 2008  & 0.207 \sym{***} & 3e-4 \sym{***} & 623 & 0.27 & 0.21 \\
                      & {(}0.049{)}     & {(}0.8e-4{)}   &     &      &      \\
                \addlinespace
        2009 -- 2015  &                 &                &     &      &      \\
                      &                 &                &     &      &      \\
                \addlinespace
            \bottomrule
        \multicolumn{5}{l}{\footnotesize Estimerte standardavvik er gitt i parenteser}\\
        \multicolumn{5}{l}{\footnotesize
            \sym{*}   $p < \num{0.05}$,
            \sym{**}  $p < \num{0.01}$,
            \sym{***} $p < \num{0.001}$}\\
    \end{tabular}
\end{document}

顯示上述程式碼結果的圖像

相關內容