[Tex/LaTex] Alignment in tables using siunitx

horizontal alignmentsiunitxtables

I am using the siunitx package to align some numbers in a table. See below for preamble

\documentclass[12pt]{report}
 \usepackage[T1]{fontenc}
 \usepackage{textcomp}
 \usepackage{booktabs}
 \usepackage{multirow}
 \usepackage{siunitx}

\begin{document}
 \begin{table}[h]
  \centering
  \sisetup{table-format=2.4}
 \begin{tabular}{@{}lSSS@{}}
    \toprule
    \textbf{Summary statistics} & \textbf{Stock1} & \textbf{Stock2} & \textbf{Stock3} \\ \midrule
    Mean                        & -0.0003       & -0.0007          & -0.0008           \\ \midrule
    Maximum                     & 0.1379           & 0.2028           & 0.0924            \\
    Minimum                     & -0.2166          & -0.1164          & -0.1306           \\ \midrule
    Standard deviation          & 0.0238           & 0.0159           & 0.0128            \\
    Skewness                    & -0.0419          & 0.4084           & -1.2155           \\
    Kurtosis                    & 6.7156           & 18.8598          & 13.5484   \\ \midrule
    Jarque-Bera                 & \multicolumn{1}{c}{11,048}  & \multicolumn{1}{c}{39,311}  & \multicolumn{1}{c}{21,206}  \\
    P-value                     & \textless 0.0001  & \textless 0.0001  & \textless 0.0001   \\ \midrule
    Observations                & \multicolumn{1}{c}{4,438}   & \multicolumn{1}{c}{2,643}   & \multicolumn{1}{c}{2,349}   \\ \bottomrule
 \end{tabular}
  \caption{{\small Summary statistics of the log returns}}
  \label{tab:SumStat}
 \end{table}
\end{document}

Output

enter image description here

I am able to align decimal numbers in the table correctly, but I also have one row of integer numbers and one row with a \textless command (the two bottom rows). My problems are:

  1. I want the integer numbers to be aligned as centered below the decimal numbers as possible (see the column for stock3 especially). I have tried using alignment r, but that pushes the number too far to the right. Is it possible to align the number something in between c and r, maybe?
  2. I want some spacing between the textless sign and the decimal number.

I would be grateful for any help!

Best Answer

Even though I'd do some things a little bit different myself, I will simply answer the specific questions you asked.

  1. To get the integer numbers centered in the column, wrap them in a group as in {4,438}, as these groups are not parsed by siunitx. Also, I wrapped your column headings in groups to get them centered. Optionally you can use \sisetup{table-format=2.4,group-separator={,},group-four-digits} with \num{4438} to make switching format later easier. If you want these numbers right-aligned, you can set table-text-alignment=right in the column setup. Note that this will also affect the column headings.

  2. To get better spacing after <, use \sisetup{table-format=<2.4}.

In conclusion, you can use the following (removed non-essential packages):

\documentclass[12pt]{report}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[h]
  \centering
  \sisetup{table-format=<2.4}
   \begin{tabular}{@{}lSSS@{}}
    \toprule
    \textbf{Summary statistics} & {\textbf{Stock1}} & {\textbf{Stock2}} & {\textbf{Stock3}} \\ \midrule
    Mean                        & -0.0003           & -0.0007           & -0.0008           \\ \midrule
    Maximum                     &  0.1379           &  0.2028           &  0.0924           \\
    Minimum                     & -0.2166           & -0.1164           & -0.1306           \\ \midrule
    Standard deviation          &  0.0238           &  0.0159           &  0.0128           \\
    Skewness                    & -0.0419           &  0.4084           & -1.2155           \\
    Kurtosis                    &  6.7156           & 18.8598           & 13.5484           \\ \midrule
    Jarque-Bera                 & {11,048}          & {39,311}          & {21,206}          \\
    P-value                     & <0.0001           & <0.0001           & <0.0001           \\ \midrule
    Observations                & {4,438}           & {2,643}           & {2,349}           \\ \bottomrule
  \end{tabular}
  \caption{{\small Summary statistics of the log returns}}
  \label{tab:SumStat}
\end{table}
\end{document}

Output

With table-text-alignment=right:

Output with table-text-alignment=right

Related Question