使用 siuntix 按小数点对齐表格中缺少小数点的负十进制数

使用 siuntix 按小数点对齐表格中缺少小数点的负十进制数

我正在尝试对齐此表中的数字,以便小数点始终位于彼此下方。这似乎适用于 siunitx 包。但是,我遇到了两个困难:

  1. 第二列中负数的小数点(尽管小数点确实显示在倒数第二列)。

  2. 尽管我没有在代码中的小数点前添加 0,但表格在编译后仍显示零。我该如何摆脱这个问题?

非常感谢你的帮助!

\documentclass[12pt]{scrreprt}

\usepackage{booktabs}
\usepackage{siunitx} 
\sisetup{input-decimal-markers={.}}
\usepackage{threeparttable}
\begin{document}

\begin{table}[h]
            \caption{new table}
            \label{tab:1a}
            \footnotesize
            \begin{threeparttable}
            \begin{tabular}{lcS[table-format=2.2]%
            S[table-format=4.2]%
            S[table-format=4.2]%
            S[table-format=4.2]%
            S[table-format=4.2]}
            \multicolumn{7}{l}{\textit{Correlations between perceived usefulness and active cognitive load for cognitive}} \\
            \multicolumn{7}{l}{\textit{and metacognitive strategies (total scores)}} \\
            \\
            \toprule
                                                            & N       & 1                & 2          & 3        & 4         & 5            \\
            \midrule
            1. Mean usefulness C.            & 96      &                  &            &          &           &               \\
            \midrule
            2. Mean active CL for C.          & 96      & -.07   &            &          &           &               \\
            \midrule
            3. Mean usefulness for M.     & 83      & .18\tnote{*}    & .25\tnote{*}       &          &           &               \\
            \midrule
            4. Mean active CL for M.      & 83      & -.13            & .67\tnote{**}      & .09      &           &               \\
            \midrule
            5. Mean usefulness for A.        & 83      & .77\tnote{**}    & .12       & .77\tnote{*}    & -.02     &                \\
            \midrule
            6. Mean active CL for A.         & 83      & -.10            & .91\tnote{**}      & .19 \tnote{*}     & .92\tnote{**}     & .06  \\
            \bottomrule \\
        %   \multicolumn{7}{l}{*. Correlation is significant at the 0.05 level (1-tailed).}        \\
        %   \multicolumn{7}{l}{**. Correlation is significant at the 0.01 level (1-tailed).}                                                             
            \end{tabular}
            \begin{tablenotes}
            \item[*] Correlation is significant at the 0.05 level (1-tailed).
            \item[**] Correlation is significant at the 0.01 level (1-tailed).
            \end{tablenotes}
            \end{threeparttable}
        \end{table}

\end{document}

现在的表格

答案1

您的数字可能有一个减号,整数部分有一位数字,小数部分有两位数字,因此规范如下

S[table-format=-1.2]
S[table-format=1.2]

分别。我将使用您放置在表格顶部的文本的标题并删除第一列中的句点。

由于 a\tnote使用零宽度,我稍微放大了\tabcolsep。我觉得\footnotesize没有必要,所以我把它注释掉了。

注意前导零这是一种很好的做法,而忽略它则不是。

\documentclass[12pt]{scrreprt}

\usepackage{booktabs}
\usepackage{siunitx} 
\sisetup{input-decimal-markers={.}}
\usepackage{threeparttable}
\begin{document}

\begin{table}[htp]
\centering
%\footnotesize

\begin{threeparttable}

\caption{Correlations between perceived usefulness and active cognitive load 
for cognitive and metacognitive strategies (total scores)}
\label{tab:1a}

\addtolength{\tabcolsep}{3pt}

\begin{tabular}{
  @{}
  l
  c
  S[table-format=-1.2]
  S[table-format=1.2]
  S[table-format=1.2]
  S[table-format=-1.2]
  S[table-format=1.2]
  @{}
}
\\
\toprule
& N & {1} & {2}  & {3} & {4} & {5} \\
\midrule
1. Mean usefulness C & 96  &  &&  &   &   \\
\midrule
2. Mean active CL for C  & 96  & -.07   &&  &   &   \\
\midrule
3. Mean usefulness for M & 83  & .18\tnote{*}& .25\tnote{*}   &  &   &   \\
\midrule
4. Mean active CL for M  & 83  & -.13& .67\tnote{**}  & .09  &   &   \\
\midrule
5. Mean usefulness for A & 83  & .77\tnote{**}& .12   & .77\tnote{*}& -.02 &\\
\midrule
6. Mean active CL for A & 83  & -.10& .91\tnote{**}  & .19 \tnote{*} & .92\tnote{**} & .06  \\
\bottomrule
\end{tabular}

\begin{tablenotes}
\item[*] Correlation is significant at the 0.05 level (1-tailed).
\item[**] Correlation is significant at the 0.01 level (1-tailed).
\end{tablenotes}

\end{threeparttable}

\end{table}

\end{document}

在此处输入图片描述

可能使用选项删除小数点分隔符前的零

print-zero-integer=false

\sisetup你会得到

在此处输入图片描述

答案2

编辑: 已考虑 OP 评论。现在十进制数没有前导整数零。

您可能喜欢以下表格格式:

在此处输入图片描述

它是通过使用 tabularray包来设置的:

\documentclass[12pt]{scrreprt}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
  \ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {3}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\begin{document}
    \begin{table}[h]
    \SetTblrStyle{foot}{font=\footnotesize}
    \sisetup{print-zero-integer=false}  % <--- for remove zero integers
\begin{talltblr}[
caption = {New table},
  label = {tab:1a},
note{*} = {Correlation is significant at the 0.05 level (1-tailed).},
note{**} = {Correlation is significant at the 0.01 level (1-tailed).},
                ]{
    colsep = {4 pt},
    colspec = {@{} l  X[c, si={table-format=2.0}]%
                      X[c, si={table-format=-1.2{**}}]
                 *{2}{X[c, si={table-format= 1.2{**}}]}
                      X[c, si={table-format=-1.2{*}}]
                      X[c, si={table-format= 1.2}]
               @{}  },
    rowsep  = 0pt,
    row{eachtwo} = {abovesep=3pt},
    row{1,2} = {rowsep=2pt},
    hspan=minimal
                  }
\SetCell[c=7]{j, font=\itshape}
     Correlations between perceived usefulness and active cognitive load for cognitive and metacognitive strategies (total scores)        
                            &         &         &         &         &         &             \\
     \toprule
                            & {{{N}}} & {{{1}}} & {{{2}}} & {{{3}}} & {{{4}}} &  {{{5}}}    \\
     \midrule
1. Mean usefulness C.       & 96      &         &         &         &         &             \\
2. Mean active CL for C.    & 96      & -.07    &         &         &         &             \\
3. Mean usefulness for M.   & 83      &  .18\TblrNote{*}  
                                                & .25\TblrNote{*}
                                                          &         &         &             \\
4. Mean active CL for M.    & 83      & -.13    & .67\TblrNote{**}
                                                          & .09     &         &             \\
5. Mean usefulness for A.   & 83      &  .77\TblrNote{**}
                                                & .12     & .77\TblrNote{*}
                                                                    & -.02    &             \\
6. Mean active CL for A.    & 83      & -.10    & .91\TblrNote{**}
                                                          & .19\TblrNote{*}
                                                                    & .92\TblrNote{*}
                                                                              & .06         \\
    \bottomrule
\end{talltblr}
    \end{table}
\end{document}

相关内容