3
\documentclass{article}
\usepackage[english]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage{booktabs}% Nicer horizontal lines
\usepackage{caption}% Fix vertical spacing of table captions
\usepackage{siunitx}% Align numbers at the decimal point

\begin{document}


\begin{table}[htbp]
    \centering
      \captionsetup{width=18cm}
      \caption{Panel A reports the minimum, maximum, mean, median, standard deviation and autocorrelation for the time series .  Panel B reports the variance-covariance matrix. The sample period is between 30/11/1900 and 11/03/2010.}
        \setlength\tabcolsep{3pt}
        \begin{tabular}{lccccccc}
        \hline
        \textit{Panel A} & \multicolumn{1}{l}{Minimum}&\multicolumn{1}{l}{Maximum}&\multicolumn{1}{l}{Mean}&\multicolumn{1}{l}{Median}&\multicolumn{1}{l}{Std}&\multicolumn{1}{l}{Autocorrelation}&\multicolumn{1}{l}{Within-Sector Correlation}\\
        \hline
        Energy & -21.99 & 10.14 & 0.01 & 0 & 1.73 & 2.96 & 54.27\\
        Agriculture I & -6.71 & 6.87 & -0.01 & -0.01 & 1.13 & 0.69 & 45.89\\
        Precious Metals & -9.21 & 8.63 & 0.01 & 0.05 & 1.4 & 4.63 & 60.13\\
        Industrial Metals & -12.4 & 12.35 & 0.03 & 0 & 1.68 & -4.15 & 100\\
        Livestock \& Meats & -4.25 & 4.06 & 0 & 0 & 1 & 2.48 & 46.03\\
        Softs & -5.89 & 7.12 & 0 & 0 & 1 & 3.19 & 8.28\\
        EWI   & -7.41 & 7.08 & 0 & 0.03 & 0.75 & 4.91 & 15.71\\
        GSCI  & -16.85 & 7.82 & 0.01 & 0.02 & 1.24 & -1.49 & -\\
        \hline\hline
        \textit{Panel B}  & \multicolumn{1}{l}{Energy} & \multicolumn{1}{l}{Agriculture} & \multicolumn{1}{l}{Precious Metals} & \multicolumn{1}{l}{Industrial Metals} & \multicolumn{1}{l}{Livestock \& Meats} & \multicolumn{1}{l}{Softs} & \multicolumn{1}{l}{EWI}\\
        \hline
        Energy & & & & & & &\\
        Agriculture I & 17 & & & & & &\\
        Precious Metals & 19 & 25 & & & & &\\
        Industrial Metals & 17 & 21 & 39 & & & &\\
        Livestock \& Meats & 6 & 12 & 8 & 10 & & &\\
        Softs & 13 & 28 & 24 & 24 & 11 & &\\
        EWI & 53 & 71 & 63 & 47 & 37 & 56 &\\
        GSCI  & 83 & 37 & 31 & 31 & 23 & 28 & 72\\
        \hline
        \end{tabular}%
      \label{tab:addlabel}%
    \end{table}%

\end{document}

I am trying to make this table work, but for some reason I can't figure out why the table is too long and the caption and the table are not aligned. I've tried several alternatives based on this site and nothing seems to work. Suggestions would be infinitely welcome!

Btw, this is initially based on using excel2latex add-in.

The outcome is:

Enter image description here

  • your table is to wide (due to long column headers) that can be fit in text area. from caption setup i conclude, that you like to have larger \textwidth. try to add \usepackage{geometry} to document preamble and than see, if obtained improvements is satisfactory. welcome to tex.se! – Zarko Jul 2 '18 at 18:58
  • Off-topic, but hyperref should be loaded after your other packages. – user36296 Jul 2 '18 at 19:53
6

One way to fit your table in text area is the following:

  • Increase text width by use of the package geometry.
  • Use smaller font in table (\small).
  • Use the macro \makecell for column headers in two lines.
  • Use tabular* table environment with prescribed width equal to \textwidth.
  • Left calculation of the \tabcolsep to the macro @{\extracolsep{\fill}}.
  • Use S column type defined in the package siunitx for align numbers at decimal points.

    \documentclass{article}
    \usepackage{geometry}
    \usepackage[english]{babel}
    \usepackage{booktabs, makecell}% nicer horizontal lines
    \usepackage{caption}% fix vertical spacing of table captions
    \usepackage{siunitx}% align numbers at the decimal point
    \usepackage[colorlinks]{hyperref}
    
    \usepackage{showframe}
    \renewcommand\ShowFrameLinethickness{0.15pt}
    \renewcommand*\ShowFrameColor{\color{red}}
    %---------------------------------------------------------------%
    
    \begin{document}
    \begin{table}[htbp]
        \centering
    %      \captionsetup{width=18cm}
          \caption{Panel A reports the minimum, maximum, mean, median, standard deviation and autocorrelation for the time series .  Panel B reports the variance-covariance matrix. The sample period is between 30/11/1900 and 11/03/2010.}
            \small
            \setlength\tabcolsep{0pt}
            \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
                                l
                                S[table-format=-2.2]
                                S[table-format= 2.2]
                           *{4}{S[table-format=-1.2]}
                                S[table-format= 2.2]
                                }
            \hline
            \textit{Panel A} & {Minimum}& {Maximum}& {Mean}& {Median}& {Std}& {\makecell{Auto-\\correlation}} & {\makecell{Within-Sector\\ Correlation}}\\
            \hline
            Energy & -21.99 & 10.14 & 0.01 & 0 & 1.73 & 2.96 & 54.27\\
            Agriculture I & -6.71 & 6.87 & -0.01 & -0.01 & 1.13 & 0.69 & 45.89\\
            Precious Metals & -9.21 & 8.63 & 0.01 & 0.05 & 1.4 & 4.63 & 60.13\\
            Industrial Metals & -12.4 & 12.35 & 0.03 & 0 & 1.68 & -4.15 & 100\\
            Livestock \& Meats & -4.25 & 4.06 & 0 & 0 & 1 & 2.48 & 46.03\\
            Softs & -5.89 & 7.12 & 0 & 0 & 1 & 3.19 & 8.28\\
            EWI   & -7.41 & 7.08 & 0 & 0.03 & 0.75 & 4.91 & 15.71\\
            GSCI  & -16.85 & 7.82 & 0.01 & 0.02 & 1.24 & -1.49 & {-}\\
            \hline\hline
            \textit{Panel B}  & {Energy} & {Agriculture} & {\makecell{Precious\\ Metals}} & {\makecell{Industrial\\ Metals}} & {\makecell{Livestock\\ \& Meats}} & {Softs} & {EWI}\\
            \hline
            Energy & & & & & & &\\
            Agriculture I & 17 & & & & & &\\
            Precious Metals & 19 & 25 & & & & &\\
            Industrial Metals & 17 & 21 & 39 & & & &\\
            Livestock \& Meats & 6 & 12 & 8 & 10 & & &\\
            Softs & 13 & 28 & 24 & 24 & 11 & &\\
            EWI & 53 & 71 & 63 & 47 & 37 & 56 &\\
            GSCI  & 83 & 37 & 31 & 31 & 23 & 28 & 72\\
            \hline
            \end{tabular*}%
          \label{tab:addlabel}%
        \end{table}%
    
    \end{document}
    

Which gives:

Wnter image description here

(Red lines indicate page layout)

Note: option [table-format=-1.2] of the column type S means and do the following:

  • Sign, -, reserve space for it (it has sense, if the number is negative).
  • 1 reserve space for integer digits (one space).
  • 2 reserve space for decimal digits (two spaces).

Besides this, options are many others. For details, see siunitx documentation, section 5.14.

  • +1 What is the @{\extracolsep{\fill}} for? – Dr. Manuel Kuehner Jul 2 '18 at 19:56
  • 2
    @Dr.ManuelKuehner, it add extra column separation to \tabcolsep. in answer \tabcolsep is set to zero, so all spaces between columns is left to this macro. – Zarko Jul 2 '18 at 20:07
  • Thank you Zarko! Your code does not run though when I click typeset (I am using TexShop). Any suggestions? Maybe some packages are not properly installed? – Daniel Pinto Jul 3 '18 at 11:47
  • @DanielPinto, difficult to say. for editor i don't use TeXShop (so i'm not familiar with it) but WinEdt (with utf8 codding). given example is tested and works fine. – Zarko Jul 3 '18 at 11:58
  • thanks @Zarko. other question: what does l S[table-format=-2.2] S[table-format= 2.2] *{4}{S[table-format=-1.2]} S[table-format= 2.2] } do? – Daniel Pinto Jul 3 '18 at 13:26
4

Here's a solution that uses two separate tabularx environments for Panel A and for Panel B. That way, alignment of the numbers on the decimal markers can be performed optimally for each panel. The columns headers are typeset using centered versions of the X column type, to allow automatic linebreaking while also assuring that the tabularx environments occupy the available space.

enter image description here

\documentclass{article}
\usepackage[english]{babel}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\usepackage{tabularx,ragged2e} % <-- new
\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}} % handy shortcut macro
\usepackage[colorlinks]{hyperref}
\begin{document}

\begin{table}[htbp]
\caption{Panel A reports the minimum, maximum, mean, median, standard 
deviation and autocorrelation for the time series.  Panel B reports 
the variance-covariance matrix. The sample period is 30/11/1900 
to 11/03/2010.}
\label{tab:addlabel}
\setlength\tabcolsep{3pt}  % default: 6pt
\begin{tabularx}{\textwidth}{@{} 
   l 
   S[table-format=-2.2]
   S[table-format=2.2]
   *{2}{S[table-format=-1.2]}
   S[table-format=1.2]
   S[table-format=-1.2]
   S[table-format=3.2] @{}}
\toprule    
\textit{Panel A} 
&\mC{Minimum}
&\mC{Maximum}
&\mC{Mean}
&\mC{Median}
&\mC{Standard Deviation}
&\mC{Autocorrelation}
&\multicolumn{1}{C@{}}{Within-Sector Correlation}\\
\midrule    
Energy & -21.99 & 10.14 & 0.01 & 0 & 1.73 & 2.96 & 54.27\\
Agriculture I & -6.71 & 6.87 & -0.01 & -0.01 & 1.13 & 0.69 & 45.89\\
Precious Metals & -9.21 & 8.63 & 0.01 & 0.05 & 1.4 & 4.63 & 60.13\\
Industrial Metals & -12.4 & 12.35 & 0.03 & 0 & 1.68 & -4.15 & 100\\
Livestock \& Meats & -4.25 & 4.06 & 0 & 0 & 1 & 2.48 & 46.03\\
Softs & -5.89 & 7.12 & 0 & 0 & 1 & 3.19 & 8.28\\
EWI   & -7.41 & 7.08 & 0 & 0.03 & 0.75 & 4.91 & 15.71\\
GSCI  & -16.85 & 7.82 & 0.01 & 0.02 & 1.24 & -1.49 & {\mbox{--}}\\
\addlinespace\midrule\addlinespace   
\end{tabularx}

\begin{tabularx}{\textwidth}{@{} 
    l *{7}{S[table-format=2.0]} @{}}
\textit{Panel B}  
& \mC{Energy}
& \mC{Agriculture}
& \mC{Precious Metals}
& \mC{Industrial Metals} 
& \mC{Livestock \& Meats} 
& \mC{Softs} 
& \multicolumn{1}{C@{}}{EWI} \\
\midrule    
Energy\\
Agriculture I & 17 \\
Precious Metals & 19 & 25\\
Industrial Metals & 17 & 21 & 39\\
Livestock \& Meats & 6 & 12 & 8 & 10\\
Softs & 13 & 28 & 24 & 24 & 11\\
EWI & 53 & 71 & 63 & 47 & 37 & 56 \\
GSCI  & 83 & 37 & 31 & 31 & 23 & 28 & 72\\
\bottomrule    
\end{tabularx}
\end{table}

\end{document}
3

I'd suggest the following in which I have split the table into two parts for the upper panel A and the lower panel B. I have also added the lines from the booktabs package as well as S type columns from the siunitx package in order to align the numbers with respect to their decimal separator. Lastly, I have split too long column headers into two rows by using makecell and adjusted the \tabcolsep.

enter image description here

\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{geometry}

\begin{document}


\begin{table}[htbp]
    \centering
      %\captionsetup{width=18cm}
      \caption{Panel A reports the minimum, maximum, mean, median, standard deviation and autocorrelation for the time series .  Panel B reports the variance-covariance matrix. The sample period is between 30/11/1900 and 11/03/2010.}
        \setlength\tabcolsep{4.85pt}
        \begin{tabular*}{\textwidth}{l
                        S[table-format=-2.2]
                        S[table-format=2.2]
                        S[table-format=-1.2]
                        S[table-format=-1.2]
                        S[table-format=1.2]
                        S[table-format=-1.2]
                        S[table-format=3.2]}
        \toprule    
        \textit{Panel A} & {Minimum}& {Maximum}& {Mean}& {Median}&{Std}& {\makecell[cc]{Auto-\\ correlation}}& {\makecell[cc]{Within-Sector\\ Correlation}}\\
        \midrule    
        Energy & -21.99 & 10.14 & 0.01 & 0 & 1.73 & 2.96 & 54.27\\
        Agriculture I & -6.71 & 6.87 & -0.01 & -0.01 & 1.13 & 0.69 & 45.89\\
        Precious Metals & -9.21 & 8.63 & 0.01 & 0.05 & 1.4 & 4.63 & 60.13\\
        Industrial Metals & -12.4 & 12.35 & 0.03 & 0 & 1.68 & -4.15 & 100\\
        Livestock \& Meats & -4.25 & 4.06 & 0 & 0 & 1 & 2.48 & 46.03\\
        Softs & -5.89 & 7.12 & 0 & 0 & 1 & 3.19 & 8.28\\
        EWI   & -7.41 & 7.08 & 0 & 0.03 & 0.75 & 4.91 & 15.71\\
        GSCI  & -16.85 & 7.82 & 0.01 & 0.02 & 1.24 & -1.49 & {-}\\
        \bottomrule
        \end{tabular*}
        \setlength\tabcolsep{6.5pt}
        \begin{tabular*}{\textwidth}{l*7{S[table-format=2]}} 
        \toprule 
        \textit{Panel B}  & {Energy} &  {Agriculture} &  {\makecell[cc]{Precious \\ Metals}} &  {\makecell[cc]{Industrial\\ Metals}} &  {\makecell[cc]{Livestock\\ \& Meats}} &  {Softs} &  {EWI}\\
        \midrule    
        Energy & & & & & & &\\
        Agriculture I & 17 & & & & & &\\
        Precious Metals & 19 & 25 & & & & &\\
        Industrial Metals & 17 & 21 & 39 & & & &\\
        Livestock \& Meats & 6 & 12 & 8 & 10 & & &\\
        Softs & 13 & 28 & 24 & 24 & 11 & &\\
        EWI & 53 & 71 & 63 & 47 & 37 & 56 &\\
        GSCI  & 83 & 37 & 31 & 31 & 23 & 28 & 72\\
        \bottomrule    
        \end{tabular*}%
      \label{tab:addlabel}%
    \end{table}%

\end{document}
3

I suggest to make two distinct tables and also to add a legend for abbreviating the long names: you need eight columns and the long headers would need awkward breaks.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs}% nicer horizontal lines
\usepackage{caption}% fix vertical spacing of table captions
\usepackage{siunitx}% align numbers at the decimal point
\usepackage[colorlinks]{hyperref}

\begin{document}

\begin{table}[htbp]
\centering
\setlength{\tabcolsep}{0pt}

\caption{Panel A reports the minimum, maximum, mean, median, 
standard deviation and autocorrelation for the time series.
Panel B reports the variance-covariance matrix. The sample 
period is between 30/11/1900 and 11/03/2010.}\label{tab:addlabel}

\captionsetup{font=footnotesize}
\caption*{Legend: (En)~Energy; (Agr)~Agriculture~I; (PM)~Precious Metals;
(IM)~Industrial Metals; (LM)~Livestock \&~Meats; (S)~Softs;
(Min)~Minimum; (Max)~Maximum; (Med)~Median; (SD)~Standard Deviation;
(A)~Autocorrelation; (WSC)~Within-Section Correlation.}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  S[table-format=-2.2]
  S[table-format=2.2]
  S[table-format=-1.2]
  S[table-format=-1.2]
  S[table-format=1.2]
  S[table-format=-1.2]
  S[table-format=3.2]
  @{}
}
\toprule
\textit{Panel A} &
 {Min} &
 {Max} &
 {Mean} &
 {Med} &
 {SD} &
 {A} &
 {WSC} \\
\midrule
En   & -21.99 & 10.14 &  0.01 &  0    & 1.73 &  2.96 &  54.27 \\
Agr  &  -6.71 &  6.87 & -0.01 & -0.01 & 1.13 &  0.69 &  45.89 \\
PM   &  -9.21 &  8.63 &  0.01 &  0.05 & 1.4  &  4.63 &  60.13 \\
IM   & -12.4  & 12.35 &  0.03 &  0    & 1.68 & -4.15 & 100    \\
LM   &  -4.25 &  4.06 &  0    &  0    & 1    &  2.48 &  46.03 \\
S    &  -5.89 &  7.12 &  0    &  0    & 1    &  3.19 &   8.28 \\
EWI  &  -7.41 &  7.08 &  0    &  0.03 & 0.75 &  4.91 &  15.71 \\
GSCI & -16.85 &  7.82 &  0.01 &  0.02 & 1.24 & -1.49 &   {--} \\
\bottomrule
\end{tabular*}
\medskip
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  *{7}{S[table-format=2.0]}
  @{}
}
\toprule
\textit{Panel B} & {En} & {Agr} & {PM} & {IM} & {LM} & {S} & {EWI} \\
\midrule
En   &    &    &    &    &    &    &    \\
Agr  & 17 &    &    &    &    &    &    \\
PM   & 19 & 25 &    &    &    &    &    \\
IM   & 17 & 21 & 39 &    &    &    &    \\
LM   &  6 & 12 &  8 & 10 &    &    &    \\
S    & 13 & 28 & 24 & 24 & 11 &    &    \\
EWI  & 53 & 71 & 63 & 47 & 37 & 56 &    \\
GSCI & 83 & 37 & 31 & 31 & 23 & 28 & 72 \\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

enter image description here

1

The column headers were way too long, so I put them into multirows (multirow package). Even still, it wasn't perfect so I messed around a bit with the margins (geometry package). Also, forcing the centering wasn't actually necessary.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage{booktabs}% nicer horizontal lines
\usepackage{caption}% fix vertical spacing of table captions
\usepackage{siunitx}% align numbers at the decimal point
\usepackage{multirow}
\usepackage{geometry}
\geometry{
    left=1.0in
}
\begin{document}

\newcommand{\mr}[1]{\multirow{2}{*}{#1}} %We'll be using this a lot so I made it a macro

\begin{table}[htbp]
        \captionsetup{width=18cm}
        \caption{Panel A reports the minimum, maximum, mean, median, standard deviation and autocorrelation for the time series .  Panel B reports the variance-covariance matrix. The sample period is between 30/11/1900 and 11/03/2010.}

        \setlength\tabcolsep{3pt}
        \begin{tabular}{lccccccc}
            \hline    
            \mr{\textit{Panel A}} & \mr{Minimum} & \mr{Maximum} & \mr{Mean} & \mr{Median} & \mr{Std} & Auto- & Within-Sector\\
            & & & & & & correlation & Correlation\\
            \hline    
            Energy & -21.99 & 10.14 & 0.01 & 0 & 1.73 & 2.96 & 54.27\\
            Agriculture I & -6.71 & 6.87 & -0.01 & -0.01 & 1.13 & 0.69 & 45.89\\
            Precious Metals & -9.21 & 8.63 & 0.01 & 0.05 & 1.4 & 4.63 & 60.13\\
            Industrial Metals & -12.4 & 12.35 & 0.03 & 0 & 1.68 & -4.15 & 100\\
            Livestock \& Meats & -4.25 & 4.06 & 0 & 0 & 1 & 2.48 & 46.03\\
            Softs & -5.89 & 7.12 & 0 & 0 & 1 & 3.19 & 8.28\\
            EWI   & -7.41 & 7.08 & 0 & 0.03 & 0.75 & 4.91 & 15.71\\
            GSCI  & -16.85 & 7.82 & 0.01 & 0.02 & 1.24 & -1.49 & -\\
            \hline\hline    
            \mr{\textit{Panel B}}  & \mr{Energy} & \mr{Agriculture} & Precious & Industrial & Livestock \& & \mr{Softs} & \mr{EWI}\\
            & & & Metals & Metals & Meats & &\\
            \hline    
            Energy & & & & & & &\\
            Agriculture I & 17 & & & & & &\\
            Precious Metals & 19 & 25 & & & & &\\
            Industrial Metals & 17 & 21 & 39 & & & &\\
            Livestock \& Meats & 6 & 12 & 8 & 10 & & &\\
            Softs & 13 & 28 & 24 & 24 & 11 & &\\
            EWI & 53 & 71 & 63 & 47 & 37 & 56 &\\
            GSCI  & 83 & 37 & 31 & 31 & 23 & 28 & 72\\
            \hline    
        \end{tabular}
        \label{tab:addlabel}
\end{table}

\end{document}

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.