Search code examples
latextabular

How to fit a Latex table to a given document size?


I tried a lot of things to fit the table to the given size of the document. Unfortunately it did not work without destroying the format.

\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[latin1]{inputenc}

\begin{document}

\begin{table}[!htbp] \centering
\begin{tabular} {@{\extracolsep{1pt}}lcc}
\\[-1.8ex]\hline
& \multicolumn{2}{c}{\textit{First Stage Regression}} \
\cr \cline{2-3}
\hline \\[-1.8ex]
\\[-1.8ex] & \multicolumn{1}{c}{  \% foreign born
while in college} & \multicolumn{1}{c}{\% foreign born
while in high
school}  \\
\\[-1.8ex] & (1) & (2) \\
\hline \\[-1.8ex]
 1960 Distribution
of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07 $^{***}$ \\
  & (8.26e+04) & (2.74e+04) \\
\hline \\[-1.8ex]
 Observations & 3,588,372 & 3,588,372 \\
 $R^2$ & 0.051 & 0.051 \\
 Adjusted $R^2$ & 0.051 & 0.051 \\
 Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371)  \\
 F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
\end{document}

Does anyone have an idea? Thanks


Solution

    • I suggest to use a table* environment so that your table will span over both columns.

    • You can safe some room by making very long cells into multi-line cells. The tabularray package makes this easy.

    • Are you 100% sure that your document is really encoded in latin1? That sounds very usual this millennium...

    • You should load the hyperref package after the other packages.

    \documentclass[10pt,a4paper,twocolumn]{article}
    \usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
    \usepackage{amsmath}
    \usepackage{graphicx}
    \usepackage[utf8]{inputenc}
    \usepackage{tabularray}
    \usepackage{hyperref}
    
    \begin{document}
    
    \begin{table*} 
    \begin{tblr}{
      colspec={X[l]X[c]X[c]},
    }
    \hline
    & \SetCell[c=2]{} \textit{First Stage Regression} & \\
    \cline{2-3}
    & \% foreign born while in college (1) & \% foreign born while in high school (2)\\
    \hline
    \SetCell[r=2]{} 1960 Distribution of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07$^{***}$ \\
    & (8.26e+04) & (2.74e+04) \\
    \hline 
    Observations & 3,588,372 & 3,588,372 \\
    $R^2$ & 0.051 & 0.051 \\
    Adjusted $R^2$ & 0.051 & 0.051 \\
    Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371)  \\
    F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
    \hline
    \hline 
    \textit{Note:} & \SetCell[c=2]{r} $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01 \\
    \end{tblr}
    \end{table*}
    \end{document}
    

    enter image description here