4

I'm trying to align the numbers within this table so that the decimal points are always underneath each other. This seems to work with the siunitx package. However, I have come across two difficulties:

  1. the decimal point for the negative numbers in the second column (though the decimal point does show on the second last column).

  2. Even though I didn't add a 0 infront of the decimal points in the code, the table shows zeros after being compiled. How do I get rid of this?

thanks so much for your help!

\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}

The table as it is now

1
  • Welcome to TeX.SE! With your MWE (Minimal Working Example) I can't reproduce your problem. It works fine.
    – Zarko
    Commented May 5, 2022 at 9:45

2 Answers 2

4

Your numbers have a possible minus sign, one digit in the integer part and two in the decimal part, so the specifications would be

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

respectively. I would use the caption for the text you place at the top of the table and remove the periods in the first column.

Since a \tnote uses zero width, I enlarge somewhat the \tabcolsep. I find \footnotesize unnecessary, so I commented it out.

Note that the leading zero is good practice and omitting it isn't.

\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}

enter image description here

You might remove the zero before the decimal separator with the option

print-zero-integer=false

in \sisetup. You'd get

enter image description here

2
  • Hi @egreg , thanks for your help! I was able to make all of the decimal points visible, however, the print-zero-integer=false option doesn't work on overleaf. Which version of siunitx do you have?
    – MadMads
    Commented May 5, 2022 at 18:39
  • @MadMads Version 3.1.0, 2022-04-25
    – egreg
    Commented May 5, 2022 at 19:23
1

Edit: Considered is OP comment. Now decimal numbers are without leading integer zero.

You may liked the following format of table:

enter image description here

It is set by use of the tabularray package:

\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}
2
  • Thanks @Zarko for your suggestion. Does the tabularray package have an option to remove the leading zeros? I have been searching for options to do this with the siunitx package but for a few years now the old commands don't seem to work anymore (e.g. \sisetup{input-decimal-markers={.}, add-integer-zero=false} )
    – MadMads
    Commented May 5, 2022 at 18:37
  • @MadMads, no. This is not its function. Handling of leading zeros is taks of siunitx package (which is loaded by tblr library siunitx). I will add this functionality ASAP. BTW, for about a year is new version od `siunitx, which make some changes in command names and options.
    – Zarko
    Commented May 5, 2022 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .