4

english is not my native language, but I will try to explain my question the best way I can.

My problem is the extra spacing between the L and T column which apparently comes when I write the numbers in scientific mode. Is there any way to have scientific numbers like this, align them on comma, and make the spacing in columns more normal (smaller) ?

Preamble:

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

Table code:

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

I hope anyone here has time to answer me. I have tried searching/googling, but I haven't found anything specific which I can use to solve my problem.

2
  • Erh, leave the formatting to the SE column, don't use \num in the column, 3.5e-4 is enough, the rest is configuration of the column. You probably also want 5 separate S columns not 5 of the same configuration
    – daleif
    Mar 22, 2016 at 17:19
  • Hopefully you don't mind that I have changed the title of your question. Now it shows the real problem and which is unique so far in the questions. Mar 22, 2016 at 20:12

1 Answer 1

4

I think your main problem are the (round) brackets used to surround your numbers, because they are also used as natural input of the \num command to indicate the error of a number. That is why you have to protect the (round) brackets by putting them into curly brackets.

(I wouldn't use your solution and add them to the input-symbols, because that could cause some undesired side effects, which I haven't tested for.)

To then get the spacing right is pretty straight forward and is already answered for example here providing the "elements" which could be found in the column to the options of the S specifier like table-format. (Have a look at table 25 of the siunitx manual v2.6 on page 47).

Have a look at the following code which I reduced a little bit, to not distract from the main tabular.

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

image showing the result of above code

3
  • Thanks a lot. I'm kind of a newbie at LaTeX and tables, and you probably saw that from my code. But this was really helpful. To be honest, I don't understand everything you did here, but I'll look into it more. Thank you very much again for your time :)
    – E-ma
    Mar 22, 2016 at 18:12
  • You are welcome. Have a look at my edited answer. Hopefully then and latest having a look at the suggested table of the manual and having a look at the following examples given there will help you to understand. If this shouldn't be sufficient, please feel free to ask again here in the comment. If you like my answer then you can -- besides accepting it -- upvote it by hitting the uparrow above the accepted mark. Mar 22, 2016 at 18:31
  • Thanks again. I'll have a look at the manual. I upvoted your answer :)
    – E-ma
    Mar 22, 2016 at 21:14

You must log in to answer this question.

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