Search code examples
latextexoverleaf

How to fit a table to the width of the page?


Im trying to create a latex table using overleaf. How can I fit this table to be shown on one page? Attached is a picture that shows how my table is currently looking like.

\documentclass{article}
\usepackage{booktabs}
\usepackage{dcolumn}
\begin{document}
\begin{table}[ht]
\caption{Summary Statistics and Sell in May Effect}
\centering
\begin{tabular}{c c c c c c c c c c}
\hline\hline 
 &  &  &  &  &  &  & t-Values of & t-Values of January\\ [0.5ex]
  &   &   &  &  &  &  & Adjusted Sell & Dummy with\\
    &  &  &  &  & & t-Values of Sell in & in May & Adjusted Sell\\
      &  &  & Mean &  &  & May Dummy & Dummy with & in May Dummy\\
     Country & Period & Observations & Return & Deviation & Alpha1 & (No January 
     Effect) & January Effect & in May Dummy\\
\hline
1 & 50 & 837 & 970 \\
2 & 47 & 877 & 230 \\
3 & 31 & 25 & 415 \\
4 & 35 & 144 & 2356 \\
5 & 45 & 300 & 556 \\ [1ex]
\hline
\end{tabular}
\label{table:nonlin} % is used to refer this table in the text
\end{table}
\end{document}

Current table


Solution

  • You could use packages like tabularx or the new tabularray which allow the table to automatically adjust to the linewidth.

    However you have sooooooooooo many columns that the result will look horrible. So in the example below, I also change the page geometry to get more space.

    \documentclass{article}
    
    \usepackage{tabularray}
    \usepackage[hmargin=1cm]{geometry}
    
    \begin{document}
    
    \begin{table}[ht]
    \caption{Summary Statistics and Sell in May Effect}
    \begin{tblr}{
      @{}ccccccX[c,valign=b]X[c,valign=b]X[c,valign=b]@{}
    }
    \hline
    \hline
    Country & 
    Period  &  
    Observations & 
    Mean Return & 
    Deviation & 
    Alpha1 & 
    t-Values of Sell in May Dummy (No January Effect) & 
    t-Values of Adjusted Sell in May Dummy with January Effect & 
    t-Values of January Dummy with Adjusted Sell in May Dummy\\
    \hline
    1 & 50 & 837 & 970 \\
    2 & 47 & 877 & 230 \\
    3 & 31 & 25 & 415 \\
    4 & 35 & 144 & 2356 \\
    5 & 45 & 300 & 556\\
    \hline
    \end{tblr}
    \label{table:nonlin} % is used to refer this table in the text
    \end{table}
    \end{document}
    

    enter image description here