2

I have a table generated in R and my point is to fit on the page cause the six column is outside the margin. The font size is set as 10. If possible I would also like to have numbers aligned to decimal separator (some numbers are negative). Any help is appreciated!

\begin{table}[!htbp]
\begin{tabular}{lllllll}
\hline \\[-1.8ex] 
\cline{2-7} 
\\[-1.8ex] & \multicolumn{6}{c}{filmweb\_rate} \\ 
\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6)\\ 
\hline \\[-1.8ex] 
 mean\_act\_rate & 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\ 
 dir.rate & 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\ 
 log(filmweb\_votes) & 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\ 
 genreAdventure & 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\ 
 genreAnimation & 0.294 & $-$0.013 & 0.381 & 0.325 & 0.010 & $-$0.093 \\ 
 genreBiography & 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\ 
 genreComedy & 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\ 
 genreCrime & $-$0.684 & $-$0.409 & $-$0.736 & $-$0.703 & $-$0.934$^{***}$ & $-$0.936$^{***}$ \\ 
\hline \\[-1.8ex] 
Observations & 796 & 796 & 796 & 796 & 796 & 796 \\ 
R$^{2}$ & 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982 \\ 
Adjusted R$^{2}$ & 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981 \\ 
Residual Std. Error (df = 759) & 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434 \\ 
F Statistic (df = 36; 759) & 85.058$^{***}$ & 120.577$^{***}$ & 78.241$^{***}$ & 81.892$^{***}$ & 203,172.700$^{***}$ & 1,150.081$^{***}$ \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 
6
  • Which documentclass do you use?
    – leandriis
    Commented Jun 19, 2020 at 16:43
  • The siunitx package can help with aligning the numbers with respect to the decimal separator.
    – leandriis
    Commented Jun 19, 2020 at 16:44
  • please always provide code as a complete test document, it is hard to say how to make something fit in a space if you do not say how big the space is. Does R really generate \\[-1.8ex] :( ? Commented Jun 19, 2020 at 16:49
  • Yes, at least stargazer package does generate it. It is article class. Sorry, mostly all my papers are article class so I assumed it by default.
    – huberttt
    Commented Jun 19, 2020 at 17:38
  • @huberttt: Did you also load the geometry package or otherwise changed the margins or the font size?
    – leandriis
    Commented Jun 19, 2020 at 17:40

2 Answers 2

2
  • for fit your table on page strongly depends from size of text area on page (which is so far unknown)
  • for horizontal rules I suggest to use rules defined in the booktabs package
  • determination of the distances between columns let be left to macro \extracolsep
  • for columns with numbers is sensible to use S column type defined in the siunitx package
  • some of above suggestion are already mentioned in comments below question
\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
\sisetup{table-space-text-post={$^{***}$},
         table-align-text-post=false,
         table-format=-1.3
         }
\setlength\tabcolsep{0pt}
    \small
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{6}{S} }
    \toprule
    &   \multicolumn{6}{c}{filmweb\_rate}           \\
    \cmidrule{2-7}
    & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} \\
    \midrule

mean\_act\_rate 
    & 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate
    & 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_votes) 
    & 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure 
    & 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation 
    & 0.294 & -0.013 & 0.381 & 0.325 & 0.010 & -0.093 \\
genreBiography 
    & 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy 
    & 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime 
    & -0.684 & -0.409 & -0.736 & -0.703 & -0.934$^{***}$ & -0.936$^{***}$ \\
    \midrule
Observations 
    & {796} & {796} & {796} & {796} & {796} & {796}     \\
R$^{2}$ 
    & 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982     \\
Adjusted R$^{2}$ 
    & 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981     \\
Residual Std. Error (df = 759) 
    & 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434     \\
F Statistic (df = 36; 759) 
    & {85.058$^{***}$} & {120.577$^{***}$}      & {78.241$^{***}$} 
    & {81.892$^{***}$} & {203,172.700$^{***}$}  & {1,150.081$^{***}$} \\
    \midrule[\heavyrulewidth]
\multicolumn{7}{l}{\textit{Note:}   
    $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tabular*}
    \end{table}
\end{document}

enter image description here

1

In addition to Zarko's answer, here are two ways to squeeze the table into the textwidth of a standard article class without loading geometry. (Red lines indicate margins.)

enter image description here

enter image description here

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{calc}


%%% do not use in actual document
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
%%%


\begin{document}

    \begin{table}[htbp]
\sisetup{table-space-text-post={$^{***}$},
         table-align-text-post=false,
         table-format=-1.3
         }
\setlength\tabcolsep{0pt}
    \footnotesize
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} >{\raggedright\arraybackslash}p{\widthof{Residual Std. Error}} *{6}{S} }
    \toprule
    &   \multicolumn{6}{c}{filmweb\_rate}           \\
    \cmidrule{2-7}
    & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} \\
    \midrule

mean\_act\_rate 
    & 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate
    & 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_votes) 
    & 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure 
    & 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation 
    & 0.294 & -0.013 & 0.381 & 0.325 & 0.010 & -0.093 \\
genreBiography 
    & 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy 
    & 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime 
    & -0.684 & -0.409 & -0.736 & -0.703 & -0.934$^{***}$ & -0.936$^{***}$ \\
    \midrule
Observations 
    & {796} & {796} & {796} & {796} & {796} & {796}     \\
R$^{2}$ 
    & 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982     \\
Adjusted R$^{2}$ 
    & 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981     \\
Residual Std. Error (df = 759) 
    & 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434     \\
F Statistic \newline(df = 36; 759) 
    & {85.058$^{***}$} & {120.577$^{***}$}      & {78.241$^{***}$} 
    & {81.892$^{***}$} & {203,172.700$^{***}$}  & {1,150.081$^{***}$} \\
    \midrule[\heavyrulewidth]
\multicolumn{7}{l}{\textit{Note:}   
    $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tabular*}
    \end{table}
    
    \begin{table}[htbp]
\sisetup{table-space-text-post={$^{***}$},
         table-align-text-post=false,
         table-format=-1.3
         }
\setlength\tabcolsep{0pt}
    \small
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} >{\raggedright\arraybackslash}p{\widthof{genreAnimation}} *{6}{S} }
    \toprule
    &   \multicolumn{6}{c}{filmweb\_rate}           \\
    \cmidrule{2-7}
    & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} \\
    \midrule

mean\_act\_rate 
    & 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate
    & 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_ votes) 
    & 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure 
    & 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation 
    & 0.294 & -0.013 & 0.381 & 0.325 & 0.010 & -0.093 \\
genreBiography 
    & 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy 
    & 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime 
    & -0.684 & -0.409 & -0.736 & -0.703 & -0.934$^{***}$ & -0.936$^{***}$ \\
    \midrule
Observations 
    & {796} & {796} & {796} & {796} & {796} & {796}     \\
R$^{2}$ 
    & 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982     \\
Adjusted R$^{2}$ 
    & 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981     \\
Residual Std. Error \newline (df = 759) 
    & 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434     \\
F Statistic \newline(df = 36; 759) 
    & {85.058$^{***}$} & {120.577$^{***}$}      & {78.241$^{***}$} 
    & {81.892$^{***}$} & {203,172.700$^{***}$}  & {1,150.081$^{***}$} \\
    \midrule[\heavyrulewidth]
\multicolumn{7}{l}{\textit{Note:}   
    $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tabular*}
    \end{table}


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .