2

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!

1

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

  • Incidentally, the Jarque-Bera statistic (a test for normality) should never be displayed as a pair of integers. It should be displazed as a positive real number. – Mico Apr 20 '16 at 10:53
  • I am open for improvements on the table if you have any, hooy. – Siso Apr 20 '16 at 21:20
0

Some comments and observations:

  • Unless you use the Jarque-Bera test for normality in a completely different way from just about everybody else in statistics and econometrics, the test statistic should be written as a positive real number, not a pair of integers.

  • I would provide a bit more structure in the table's header -- see below.

  • I wonder what readers are supposed to take away from numbers that are stated to four decimal places of precision. Seriously, providing only three digits significantly raises the odds that your readers will actually pay attention to the numbers. :-) Fortunately, siunitx can provide automatic rounding of numbers in an S column.

  • Use fewer horizontal lines, as they can be quite disruptive visually. Consider just providing a bit of (vertical) whitespace.

  • Encase items that should be centered in an S-type column in curly braces. No need to write \multicolumn{1}{c}{...}.

enter image description here

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

\begin{document}

 \begin{table}[h]
  \centering
  \sisetup{table-format=-1.3,round-mode=places,round-precision=3}
 \begin{tabular}{@{}lSSS@{}}
    \toprule
    \textbf{Summary statistic} & \multicolumn{3}{c@{}}{\textbf{Stock}}\\
    \cmidrule(l){2-4}
    & {1} & {2} & {3} \\ 
    \midrule
    Mean               & -0.0003 & -0.0007 & -0.0008 \\
    \addlinespace
    Maximum            &  0.1379 & 0.2028  & 0.0924  \\
    Minimum            & -0.2166 & -0.1164 & -0.1306 \\
    \addlinespace
    Standard deviation &  0.0238 & 0.0159  & 0.0128  \\
    \addlinespace
    Skewness           & -0.0419 & 0.4084  & -1.2155 \\
    Kurtosis           &  6.7156 & 18.8598 & 13.5484 \\
    Jarque-Bera test   & 11.048  & 39.311  & 21.206  \\
    P-value            & {$<0.0001$}  & {$<0.0001$}  & {$<0.0001$}  \\ 
    \addlinespace
    Observations       & {4,438}  & {2,643}  & {2,349} \\
    \bottomrule
 \end{tabular}
 \caption{Summary statistics of daily log stock returns}
 \label{tab:SumStat}
 \end{table}
\end{document}
  • Thanks for the observations. About the first pointer, I may have a wrongful meaning of the word "integer", but the numbers of the Jarque-Bera test are whole numbers with commas as thousand-separators (the first number is for instance "eleven thousand and forty eight"). Is this still the wrong way to state the JB-value? About the third pointer: the reason why it's four decimals is that the first mean equals to zero when rounding it up, and I want to have the same number of decimals throughout the table. But, yes, I see your point. – Siso Apr 20 '16 at 21:15
  • @Siso - The wikipedia entry on the Jarque-Bera test states that the JB test statistic is a positive, real-valued scalar. Please provide a reference for your view that the JB test is integer-valued. – Mico Apr 20 '16 at 22:37
  • I have no reference, the only thing I was trying to do was to print the test-statistic of the JB-test which I got from R. The test statistic for stock 1 was 11048,2. I felt there was no need to print the decimal, so I rounded it to 11048. With the formatting I am using, this number is then printed as 11,048. As I said in the last comment, I might have been wrong stating that this number was an integer(?). My goal with that statement was to emphasize that the (printed) number does not contain any decimals. – Siso Apr 21 '16 at 13:16
  • @Siso - Many thanks for providing these clarifications. I realize now that I was completely thrown off-track by the presence of the commas and the absence of decimal markers in the statistics. Anyway, I wouldn't use commas as thousands-separators in the table at hand, as they may easily be misinterpreted. I would use either thin-spaces or no thousands-separators at all. – Mico Apr 21 '16 at 16:53
0

Here is a solution, cheating with the number of decimal digits. Also, I think the table looks better without the last @ in the table preamble:

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

 \begin{document}

 \begin{table}[h]
  \centering
  \sisetup{table-format=-1.6, table-number-alignment=center, table-comparator}
 \begin{tabular}{@{}lSSS}
    \toprule
    \textbf{Summary statistics} &{ \textbf{Stock1}} & {\textbf{Stock2}} & {\textbf{Stock3}} \\ \midrule
    Mean & -0.0003 & -0.0007 & -0.0008 \\ \cmidrule(r){1-4}
    Maximum & 0.1379 & 0.2028 & 0.0924 \\
    Minimum & -0.2166 & -0.1164 & -0.1306 \\ \cmidrule(r){1-4}
    Standard deviation & 0.0238 & 0.0159 & 0.0128 \\
    Skewness & -0.0419 & 0.4084 & -1.2155 \\
    Kurtosis & 6.7156 & 18.8598 & 13.5484 \\ \cmidrule(r){1-4}
    Jarque-Bera & {11,048} & {39,311} & {21,206} \\
    P-value & {$<\negmedspace 0.0001 $} & {$<\negmedspace 0.0001 $} & {$<\negmedspace 0.0001$} \\ \cmidrule(r){1-4}
    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} 

enter image description here

  • Do note that the Jarque-Bera tests should be positive real numbers rather than comma-separated pairs of integers. Not sure why the OP used commas rather than dots in Jarque-Bera row. – Mico Apr 20 '16 at 14:46
  • I hadn't even heard of this test, so I thought this row was made up of integers with a thousand separator :o) – Bernard Apr 20 '16 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.