4

I'm trying to align the value of a summary statistic latex table. Here is the code I used:

  \documentclass[a4paper, 11pt]{article}
 \usepackage{amsmath}
\usepackage{booktabs}
\usepackage{amsmath}
  \usepackage{multirow}
  \usepackage{array}
 \usepackage{multirow}
  \usepackage{booktabs}
 \usepackage{tabulary}
   \usepackage{float}
  \usepackage{tabularx}
  \usepackage{rotating}
 \usepackage{siunitx}
  \usepackage{booktabs, makecell, multirow, threeparttable}
  \usepackage{caption}
  \usepackage{multirow}
  \usepackage[utf8]{inputenc}
   \usepackage{multirow}
\usepackage{makecell}
  \usepackage{siunitx,booktabs}
   \usepackage[left = 2.5cm, right = 2.5cm]{geometry}
    \usepackage{adjustbox}

 \begin{document}

  \begin{table}[H]
    \caption{Descriptive statistics}
      \label{tab:statistics}
   \begin{tabular}{lcS[table-format=1.1]
S[table-format=1.1]
S[table-format=1.3]
S[table-format=1.3]
S[table-format=1.2]
S[table-format=1.1]
  S[table-format=1.1]
     }
       \toprule
      {Statistic}             & {Mean}   & {St. Dev.}& {Min}    & {Max}   & {Skewness} & {Kurtosis} &
       {Jarque-Bera} & {N}\\
         \midrule
          GNP growth (y)          & 0.55319  &   0.7904   &   -2.65  &  2.09   &  -1.320    & 6.1412
                      &
                     79.991  &  114  \\
                GNP deflator (P)         & 0.6671   &   0.7647  &   -0.16  &  2.7250 &  2.0248    &
                              7.2870  &
                            165.20  &  114   \\
                          Unemployment (U)         & 6.0970   &   1.4535  &   3.90   &  10.53   &
                         0.9229    & 3.7673  & 18.982  & 114     \\
                         BAA corporate bonds (S)   & 2.3745   &   0.7904 &   1.080  & 5.8200  &
                       1.5670    & 7.2624  & 133.00  & 114    \\
                          House Price index (HPI)    & 129.22  &   40.519 &  75.30   & 202.5  &
                    0.0184    & 1.5491  & 10.004  & 114    \\
                    S\&P 500   index         & 1173.83  &  561.45   &  317.05  & 2732.5 &   0.4946
                & 2.8919  & 4.7046  & 114    \\
                   \bottomrule
                   \end{tabular}
                       \end{table}

                        \end{document}

Enter image description here

  • 2
    Your document is not compilable since ou loead the geometry package twice and with different options. Make sure you don't load packages more than once. This also applies to other packages. You for example load multirow 5 times! – leandriis Apr 3 at 8:58
  • Regarding the alignment: The numbers are not aligned correctly, because the values of table-format you used are not correct. table-format=1.2 would imply that your column only contains numbers with 1 place before the decimal separator and 2 decimal places. Your "Skewnwee" column for example has numbers with 4 decimal places. This would correspond to [table-format=-1.4]. – leandriis Apr 3 at 9:03
  • Perhaps fix the indentation and vertical alignment in the source? It seems to be all over the place. – Peter Mortensen Apr 4 at 3:12
2

Here are two versions. In both I have corrected the use of table-format as already mentioned in a comment. To make the table fit into the textwidth I have reduced the font size and included two alternatives using either tabularx or tabular*:

enter image description here

\documentclass[a4paper, 11pt]{article} 
\usepackage{booktabs} 
\usepackage{siunitx}
\usepackage{caption}
\usepackage{tabularx}
\usepackage[a4paper,left = 2.5cm, right = 2.5cm]{geometry}


 \begin{document}

  \begin{table}
    \caption{Descriptive statistics}
    \setlength{\tabcolsep}{4pt}
    \small
      \label{tab:statistics}
   \begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}X
                   S[table-format=4.5]
                   S[table-format=3.4]
                   S[table-format=-3.3]
                   S[table-format=4.4]
                   S[table-format=-1.4]
                   S[table-format=1.4]
                   S[table-format=3.4]
                   S[table-format=3]
     }
       \toprule
      {Statistic}             & {Mean}   & {St. Dev.}& {Min}    & {Max}   & {Skewness} & {Kurtosis} & 
       {Jarque-Bera} & {N}\\
         \midrule
          GNP growth (y)          & 0.55319  &   0.7904   &   -2.65  &  2.09   &  -1.320    & 6.1412  
                      & 
                     79.991  &  114  \\
                GNP deflator (P)         & 0.6671   &   0.7647  &   -0.16  &  2.7250 &  2.0248    & 
                              7.2870  & 
                            165.20  &  114   \\
                          Unemployment (U)         & 6.0970   &   1.4535  &   3.90   &  10.53   &  
                         0.9229    & 3.7673  & 18.982  & 114     \\
                         BAA corporate bonds (S)   & 2.3745   &   0.7904 &   1.080  & 5.8200  &  
                       1.5670    & 7.2624  & 133.00  & 114    \\
                          House Price index (HPI)    & 129.22  &   40.519 &  75.30   & 202.5  &  
                    0.0184    & 1.5491  & 10.004  & 114    \\
                    S\&P 500   index         & 1173.83  &  561.45   &  317.05  & 2732.5 &   0.4946    
                & 2.8919  & 4.7046  & 114    \\                  
                   \bottomrule
                   \end{tabularx}
                       \end{table}


  \begin{table}
    \caption{Descriptive statistics}
    \setlength{\tabcolsep}{0pt}
    \footnotesize
      \label{tab:statistics}
   \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l
                   S[table-format=4.5]
                   S[table-format=3.4]
                   S[table-format=-3.3]
                   S[table-format=4.4]
                   S[table-format=-1.4]
                   S[table-format=1.4]
                   S[table-format=3.4]
                   S[table-format=3]
     }
       \toprule
      {Statistic}             & {Mean}   & {St. Dev.}& {Min}    & {Max}   & {Skewness} & {Kurtosis} & 
       {Jarque-Bera} & {N}\\
         \midrule
          GNP growth (y)          & 0.55319  &   0.7904   &   -2.65  &  2.09   &  -1.320    & 6.1412  
                      & 
                     79.991  &  114  \\
                GNP deflator (P)         & 0.6671   &   0.7647  &   -0.16  &  2.7250 &  2.0248    & 
                              7.2870  & 
                            165.20  &  114   \\
                          Unemployment (U)         & 6.0970   &   1.4535  &   3.90   &  10.53   &  
                         0.9229    & 3.7673  & 18.982  & 114     \\
                         BAA corporate bonds (S)   & 2.3745   &   0.7904 &   1.080  & 5.8200  &  
                       1.5670    & 7.2624  & 133.00  & 114    \\
                          House Price index (HPI)    & 129.22  &   40.519 &  75.30   & 202.5  &  
                    0.0184    & 1.5491  & 10.004  & 114    \\
                    S\&P 500   index         & 1173.83  &  561.45   &  317.05  & 2732.5 &   0.4946    
                & 2.8919  & 4.7046  & 114    \\                  
                   \bottomrule
                   \end{tabular*}
                       \end{table}

                        \end{document}
| improve this answer | |
4

Take your time to polish your code. Even if spaces are not significant, a good alignment will make the input more readable.

I left only the necessary packages, add the ones you really need. Don't just pile upon what you found in some template.

It's also important to state precisely what kind of figures you have in each S column. In the second one, I chose table-format=3.3, because the minus sign is shorter than two digits.

\documentclass[a4paper, 11pt]{article} 
\usepackage[left = 2.5cm, right = 2.5cm]{geometry}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{caption}

\begin{document}

\begin{table}[htp]
\caption{Descriptive statistics}
\label{tab:statistics}

\footnotesize
\setlength{\tabcolsep}{0pt} % leave the computations to TeX

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  c
  S[table-format=3.4]
  S[table-format=3.3]
  S[table-format=4.4]
  S[table-format=-1.4]
  S[table-format=1.4]
  S[table-format=3.4]
  S[table-format=3.0]
  @{}
}
\toprule
{Statistic} &
{Mean} &
{St. Dev.} &
{Min} &
{Max} &
{Skewness} &
{Kurtosis} & 
{Jarque-Bera} &
{N}\\
\midrule
GNP growth (y)          & 0.55319 &   0.7904 &  -2.65  &   2.09   & -1.320  & 6.1412 &  79.991  & 114 \\
GNP deflator (P)        & 0.6671  &   0.7647 &  -0.16  &   2.7250 &  2.0248 & 7.2870 & 165.20   & 114 \\
Unemployment (U)        & 6.0970  &   1.4535 &   3.90  &  10.53   &  0.9229 & 3.7673 &  18.982  & 114 \\
BAA corporate bonds (S) & 2.3745  &   0.7904 &   1.080 &   5.8200 &  1.5670 & 7.2624 & 133.00   & 114 \\
House Price index (HPI) & 129.22  &  40.519  &  75.30  & 202.5    &  0.0184 & 1.5491 &  10.004  & 114 \\
S\&P 500   index        & 1173.83 & 561.45   & 317.05  & 2732.5   &  0.4946 & 2.8919 &   4.7046 & 114 \\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

enter image description here

| improve this answer | |
  • is there a need for the second c column – js bibra Apr 3 at 13:27
  • @jsbibra The “Mean” values are not comparable to each other, so it is better not to align them at the decimal point. Possibly the same could be for the Min and Max columns. – egreg Apr 3 at 13:29
3

enter image description here

  \documentclass[a4paper, 11pt]{article} 
% \usepackage{amsmath}
%\usepackage{booktabs}
%\usepackage{amsmath}
%  \usepackage{multirow}
%  \usepackage{array}
% \usepackage{multirow} 
%  \usepackage{booktabs}
% \usepackage{tabulary} 
   \usepackage{float} 
%  \usepackage{tabularx}
%  \usepackage{rotating}
% \usepackage{siunitx}
%  \usepackage{booktabs, makecell, multirow, threeparttable}
%  \usepackage{caption}
%  \usepackage{multirow}
%  \usepackage[utf8]{inputenc}
%   \usepackage{multirow}
%\usepackage{makecell}
  \usepackage{siunitx,booktabs}
%   \usepackage[a4paper]{geometry}
   \usepackage[left = .5cm, right = .5cm]{geometry}
%    \usepackage{adjustbox}

 \begin{document}
\noindent
  \begin{table}[H]
    \caption{Descriptive statistics}
      \label{tab:statistics}
   \begin{tabular}{lS[table-format=4.5]S[table-format=3.4]
S[table-format=3.3]
S[table-format=4.4]
S[table-format=1.4]
S[table-format=1.4]
S[table-format=3.3]
  S[table-format=3.0]
     }  \toprule
      {Statistic} & {Mean} & {St. Dev.}& {Min} & {Max} & {Skewness} & {Kurtosis} & {Jarque-Bera} & {N}\\     \midrule
          GNP growth (y) & 0.55319  &   0.7904   &   -2.65  &  2.09   &  -1.320    & 6.1412  & 79.991  &  114  \\
          GNP deflator (P)  & 0.6671   &   0.7647  &   -0.16  &  2.7250 &  2.0248    &   7.2870  &   165.20  &  114   \\
          Unemployment (U) & 6.0970   &   1.4535  &   3.90   &  10.53   &  0.9229    & 3.7673  & 18.982  & 114     \\
          BAA corporate bonds (S)   & 2.3745   &   0.7904 &   1.080  & 5.8200  & 1.5670    & 7.2624  & 133.00  & 114    \\
          House Price index (HPI)    & 129.22  &   40.519 &  75.30   & 202.5  &  0.0184    & 1.5491  & 10.004  & 114    \\
   S\&P 500   index & 1173.83  &  561.45   &  317.05  & 2732.5 &   0.4946 & 2.8919  & 4.7046  & 114    \\ \bottomrule
                   \end{tabular}
                       \end{table}

                        \end{document}
| improve this answer | |

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.