3

I have a table that I've formatted like this:

\begin{table}[h!]
    \begin{center}
        \begin{tabular}[t]{cccc}
            \hline
        {Combo} &   {$|r|>0.5$} &   {$n>100$}   &   {$r^2n$} \\
        \hline
        {U-V}   &   0.558545    &   11640   &   3631.36 \\
        {U-R}   &   0.567270    &   11632   &   3743.12 \\
        {U-I}   &   0.579188    &   11626   &   3900.04 \\
        {U-J}   &   0.536106    &   3709    &   1066 \\
        {U-K}   &   0.535644    &   3730    &   1070.19 \\
        {B-V}   &   0.580019    &   11884   &   3998.04 \\
        {B-R}   &   0.574867    &   11763   &   3887.34 \\
        {B-I}   &   0.591288    &   11749   &   4107.7 \\
        {V-U}   &   -0.558545   &   11640   &   3631.36 \\
        {V-B}   &   -0.580019   &   11884   &   3998.04 \\
        {R-U}   &   -0.567270   &   11632   &   3743.12 \\
        {R-B}   &   -0.574867   &   11763   &   3887.34 \\
        {R-W2}  &   -0.535443   &   4022    &   1153.1 \\
        {I-U}   &   -0.579188   &   11626   &   3900.04 \\
        {I-B}   &   -0.591288   &   11749   &   4107.7 \\
        {I-W2}  &   -0.574056   &   4020    &   1324.75 \\
        {J-U}   &   -0.536106   &   3709    &   1066 \\
        {J-W2}  &   -0.577232   &   1943    &   647.401 \\
        {K-U}   &   -0.535644   &   3730    &   1070.19 \\
        {K-W1}  &   -0.512554   &   1938    &   509.136 \\
        {K-W2}  &   -0.591156   &   1960    &   684.953 \\
        {W1-K}  &   0.512554    &   1938    &   509.136 \\
        {W2-R}  &   0.535443    &   4022    &   1153.1 \\
        {W2-I}  &   0.574056    &   4020    &   1324.75 \\
        {W2-J}  &   0.577232    &   1943    &   647.401 \\
        {W2-K}  &   0.591156    &   1960    &   684.953 \\
        \hline
    \end{tabular}
\caption[Best photometric colours from the MgII dataset]{Photometric colours with highest r-value from the MgII dataset.}
\label{table:MgII_colours}
    \end{center}
\end{table}

to produce:

enter image description here

but I need the numerical columns aligned on the decimal points. From this question I tried formatting it as

    \begin{table}
    \centering
    \addtolength{\tabcolsep}{-0.3pt}
    \begin{tabular}{
                        @{}
            l
            S[table-format=1.2]
            S[table-format=1.2]
            S[table-format=2.3]         
                        @{}
        }
        \hline
        {Combo} &   {$|r|>0.5$} &   {$n>100$}   &   {$r^2n$} \\
        \hline
        {U-V}   &   0.558545    &   11640   &   3631.36 \\
        {U-R}   &   0.567270    &   11632   &   3743.12 \\
        {U-I}   &   0.579188    &   11626   &   3900.04 \\
        {U-J}   &   0.536106    &   3709    &   1066 \\
        {U-K}   &   0.535644    &   3730    &   1070.19 \\
        {B-V}   &   0.580019    &   11884   &   3998.04 \\
        {B-R}   &   0.574867    &   11763   &   3887.34 \\
        {B-I}   &   0.591288    &   11749   &   4107.7 \\
        {V-U}   &   -0.558545   &   11640   &   3631.36 \\
        {V-B}   &   -0.580019   &   11884   &   3998.04 \\
        {R-U}   &   -0.567270   &   11632   &   3743.12 \\
        {R-B}   &   -0.574867   &   11763   &   3887.34 \\
        {R-W2}  &   -0.535443   &   4022    &   1153.1 \\
        {I-U}   &   -0.579188   &   11626   &   3900.04 \\
        {I-B}   &   -0.591288   &   11749   &   4107.7 \\
        {I-W2}  &   -0.574056   &   4020    &   1324.75 \\
        {J-U}   &   -0.536106   &   3709    &   1066 \\
        {J-W2}  &   -0.577232   &   1943    &   647.401 \\
        {K-U}   &   -0.535644   &   3730    &   1070.19 \\
        {K-W1}  &   -0.512554   &   1938    &   509.136 \\
        {K-W2}  &   -0.591156   &   1960    &   684.953 \\
        {W1-K}  &   0.512554    &   1938    &   509.136 \\
        {W2-R}  &   0.535443    &   4022    &   1153.1 \\
        {W2-I}  &   0.574056    &   4020    &   1324.75 \\
        {W2-J}  &   0.577232    &   1943    &   647.401 \\
        {W2-K}  &   0.591156    &   1960    &   684.953 \\
        \hline
    \end{tabular}
    \caption[Best photometric colours from the MgII dataset]{Photometric colours with highest r-value from the MgII dataset.}
    \label{table:MgII_colours}

\end{table}

but it made this:

enter image description here

Why has it squashed up the middle two columns? I'm quite new to LaTex, and very new to siunitx. Also, is there any way to avoid having to put the braces around the textual column entries? It's kind of a pain when there are a lot of rows.

1 Answer 1

2

You just need to set appropriate values in your table-formats. In your case, you have to worry about the number of digits before and after the decimal separator and, in the second column, the presence of the sign.

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}
\begin{table}
  \centering
  \addtolength{\tabcolsep}{-0.3pt}
  \sisetup{group-digits=integer}
  \begin{tabular}{
    @{}
    l
    S[table-format=+1.6]
    S[table-format=5.0]
    S[table-format=4.3]
    @{}
    }
    \toprule
    Combo & {$|r|>0.5$} & {$n>100$} & {$r^2n$} \\
    \midrule
    U-V   & 0.558545    & 11640     & 3631.36  \\
    U-R   & 0.567270    & 11632     & 3743.12  \\
    U-I   & 0.579188    & 11626     & 3900.04  \\
    U-J   & 0.536106    & 3709      & 1066     \\
    U-K   & 0.535644    & 3730      & 1070.19  \\
    B-V   & 0.580019    & 11884     & 3998.04  \\
    B-R   & 0.574867    & 11763     & 3887.34  \\
    B-I   & 0.591288    & 11749     & 4107.7   \\
    V-U   & -0.558545   & 11640     & 3631.36  \\
    V-B   & -0.580019   & 11884     & 3998.04  \\
    R-U   & -0.567270   & 11632     & 3743.12  \\
    R-B   & -0.574867   & 11763     & 3887.34  \\
    R-W2  & -0.535443   & 4022      & 1153.1   \\
    I-U   & -0.579188   & 11626     & 3900.04  \\
    I-B   & -0.591288   & 11749     & 4107.7   \\
    I-W2  & -0.574056   & 4020      & 1324.75  \\
    J-U   & -0.536106   & 3709      & 1066     \\
    J-W2  & -0.577232   & 1943      & 647.401  \\
    K-U   & -0.535644   & 3730      & 1070.19  \\
    K-W1  & -0.512554   & 1938      & 509.136  \\
    K-W2  & -0.591156   & 1960      & 684.953  \\
    W1-K  & 0.512554    & 1938      & 509.136  \\
    W2-R  & 0.535443    & 4022      & 1153.1   \\
    W2-I  & 0.574056    & 4020      & 1324.75  \\
    W2-J  & 0.577232    & 1943      & 647.401  \\
    W2-K  & 0.591156    & 1960      & 684.953  \\
    \bottomrule
  \end{tabular}
  \caption[Best photometric colours from the MgII dataset]{Photometric colours with highest r-value from the MgII dataset.}
  \label{table:MgII_colours}
\end{table}

\end{document}

enter image description here

6
  • Ah that's better! Is there any way to avoid having to put the braces around the text values in the first column? Maybe a column format specifier or something?
    – Jim421616
    Nov 13, 2018 at 20:41
  • 1
    @Jim421616 Your first column is an l type column, so as far as I know, you don't need the brace protection there already.
    – gusbrs
    Nov 13, 2018 at 20:43
  • @Jim421616 I've added some small improvements (booktabs, in particular, but also better digit groupint).
    – gusbrs
    Nov 13, 2018 at 20:57
  • Ok, so what does the line \sisetup{group-digits=integer} do exactly?
    – Jim421616
    Nov 13, 2018 at 23:38
  • 1
    @Jim421616 It introduces grouping for larger numbers, but only for the integer part. siunitx's default is to put a thin space between groups and to group by three digits, but doesn't separate a single digit (that is, you must have at least five numbers for the grouping to take place). Notice the five digit numbers in your third column, and you'll see what's going on.
    – gusbrs
    Nov 13, 2018 at 23:47

You must log in to answer this question.

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