[Tex/LaTex] Long, sideways, fit to textwidth table from stargazer

longtablesidewaystabletables

I currently have a regression output from Stargazer (r package), which I edited into a sideways table, and made it fit to textwidth. However I wanted to try and split the table into 2 pages, in the current format (so also fit to textwidth and sideways), but I haven't been able to figure this out. I've tried lscape and longtable, but I always lose one of the three components when I attempt this.

Does anyone have a working solution? My code and the current table output is shown below.

My current code which cannot be in longtable format:

  \documentclass[12pt]{article}
  \usepackage[figuresleft]{rotating}

   \begin{sidewaystable}[h!] \centering
      \caption{Results of regression analysis} 
      \label{} 
    \resizebox{\textwidth}{!}{\begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} } 
    *lot of table data *
    *lot of table data *
    \end{tabular}} 
    \end{sidewaystable} 

Another code which I tried using lscape and longtable but ends in an error log:

documentclass[12pt]{article}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{lscape}

\begin{landscape}
\resizebox{\textwidth}{!}{\begin{longtable}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} } 
  \caption{Results of regression analysis} 
  \label{} 
*lot of data*
*lot of data*
\end{longtable}}
\end{landscape}

In both cases I use geometry for page layout with

\newgeometry{left=30mm,right=30mm,top=20mm}

Best Answer

I am making the following assumptions:

  • You're working on common class (such as article)
  • You're working with a4paper size

I had to fix some things in your code and add packages to work etc.

My trick was to divide the two last rows (Residual error and F) into 4 rows, hope that is not a problem for you. With this solution it was not necessary to change the document margins. Because other then that, the table would never fit a a4paper, regardless of the orientation.

I was also unable to break the table at a column, longtable and others work only for rows...

Packages:

threeparttablex allows for a proper longtable notes with possible labeling and cross-references etc. Read more in the manual: here.

booktabs for more professional looking tabs and to avoid wasting space.

pdflscape to rotate the pages but still allow normal printing.

longtable and multirow are kind of obvious.

longtable

\documentclass[a4paper]{article}
\usepackage{threeparttablex} 
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{multirow}

 \begin{document}
\begin{landscape}
\begin{ThreePartTable} 
 %
\begin{TableNotes}
\item[a]  A note
\item[**] Another note
\end{TableNotes}
%
    \begin{longtable}{ccccccccc}    
    \caption{Results of regression analysis} \\
\toprule
     & \multicolumn{8}{c}{\textit{Dependent variable:}}\label{tab:exper_24} \\ 
    \cmidrule{2-9}
    \\[-1.8ex] & \multicolumn{8}{c}{Fill.Rate} \\ 
    \\[-1.8ex] & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)} & \multicolumn{1}{c}{(7)} & \multicolumn{1}{c}{(8)}\\ 
%
     ASC.TypeCRC & 0.193 & 0.135 & 0.151 & 0.153 &  &  &  & 0.044 \\ 
      & (0.087) & (0.089) & (0.063) & (0.078) &  &  &  & (0.044) \\ 
      ASC.TypeCSP & 0.159 & 0.142 & 0.076 & 0.301 &  &  &  &  \\ 
      & (0.096) & (0.096) & (0.064) & (0.150) &  &  &  &  \\ 
      ASC.TypeFSC & 0.468\tnote{a} & 0.470 &  &  &  &  &  &  \\ 
      & (0.093) & (0.093) &  &  &  &  &  &  \\ 
      ASC.TypeMSC & 0.292\tnote{**} & 0.287 & 0.127 & 0.134 &  &  &  &  \\ 
      & (0.035) & (0.035) & (0.028) & (0.055) &  &  &  &  \\ 
      ASC.TypeOthers & -0.103 & -0.111 & -0.232 & 0.208 &  &  &  &  \\ 
      & (0.096) & (0.096) & (0.120) & (0.235) &  &  &  &  \\ 
      Mdemand &  & 0.00003 &  &  &  &  &  &  \\ 
      &  & (0.00001) &  &  &  &  &  &  \\ 
      Target.CustomerGSPN & 0.087 & 0.090 & 0.094 &  &  & 0.144 &  &  \\ 
      & (0.040) & (0.040) & (0.033) &  &  & (0.044) &  &  \\ 
      Target.CustomerNormal order & -0.104 & -0.096 & 0.086 &  &  & 0.098 &  &  \\ 
      & (0.028) & (0.028) & (0.026) &  &  & (0.033) &  &  \\ 
      OFS.Order.Ratio &  &  &  & 0.150 & 0.065 &  & 0.214 & 0.049 \\ 
      &  &  &  & (0.060) & (0.043) &  & (0.097) & (0.038) \\ 
      Confirm.Ratio &  &  &  & -0.006 & -0.034 &  & -0.036 & 0.035 \\ 
      &  &  &  & (0.063) & (0.049) &  & (0.095) & (0.040) \\ 
      ROP &  &  &  & -0.008 & -0.002 &  & -0.010 & -0.003 \\ 
      &  &  &  & (0.005) & (0.003) &  & (0.009) & (0.002) \\ 
      OUL &  &  &  & 0.009 & 0.002 &  & 0.013 & 0.004 \\ 
      &  &  &  & (0.005) & (0.003) &  & (0.008) & (0.002) \\ 
      MDQ &  &  &  & 0.025 & -0.011 &  & 0.046 & -0.003 \\ 
      &  &  &  & (0.029) & (0.029) &  & (0.041) & (0.027) \\ 
      Stock.accuracy.Target1 & 0.168 & 0.069 & 0.100 & 0.026 & 0.010 & 0.251 & 0.005 &  \\ 
      & (0.102) & (0.107) & (0.071) & (0.083) & (0.048) & (0.159) & (0.165) &  \\ 
      Stock.Accuracy &  &  &  &  &  &  &  & 0.198 \\ 
      &  &  &  &  &  &  &  & (0.073) \\ 
      Constant & 0.580 & 0.570 & 0.685 & 0.576 & 0.888 & 0.669 & 0.526 & 0.670 \\ 
      & (0.026) & (0.026) & (0.021) & (0.047) & (0.058) & (0.026) & (0.073) & (0.080) \\ 
     \midrule
    Observations & \multicolumn{1}{c}{1,737} & \multicolumn{1}{c}{1,737} & \multicolumn{1}{c}{508} & \multicolumn{1}{c}{170} & \multicolumn{1}{c}{40} & \multicolumn{1}{c}{344} & \multicolumn{1}{c}{109} & \multicolumn{1}{c}{38} \\ 
    R$^{2}$ & \multicolumn{1}{c}{0.105} & \multicolumn{1}{c}{0.110} & \multicolumn{1}{c}{0.109} & \multicolumn{1}{c}{0.282} & \multicolumn{1}{c}{0.109} & \multicolumn{1}{c}{0.041} & \multicolumn{1}{c}{0.118} & \multicolumn{1}{c}{0.312} \\ 
    Adjusted R$^{2}$ & \multicolumn{1}{c}{0.101} & \multicolumn{1}{c}{0.105} & \multicolumn{1}{c}{0.096} & \multicolumn{1}{c}{0.237} & \multicolumn{1}{c}{-0.052} & \multicolumn{1}{c}{0.032} & \multicolumn{1}{c}{0.066} & \multicolumn{1}{c}{0.152} \\
    \addlinespace[0.5em] 
    \multirow{2}{*}{Residual Std. Error} & \multicolumn{1}{c}{0.382} & \multicolumn{1}{c}{0.382} & \multicolumn{1}{c}{0.238)} & \multicolumn{1}{c}{0.210} & \multicolumn{1}{c}{0.086} & \multicolumn{1}{c}{0.271)} & \multicolumn{1}{c}{0.248)} & \multicolumn{1}{c}{0.068} \\ 
     & \multicolumn{1}{c}{df = 1728} & \multicolumn{1}{c}{df = 1727} & \multicolumn{1}{c}{df = 500} & \multicolumn{1}{c}{df = 159} & \multicolumn{1}{c}{df = 33} & \multicolumn{1}{c}{df = 340} & \multicolumn{1}{c}{df = 102} & \multicolumn{1}{c}{df = 30} \\
     \addlinespace[0.5em]    
    \multirow{2}{*}{F Statistic} & \multicolumn{1}{c}{25.366} & \multicolumn{1}{c}{23.665} & \multicolumn{1}{c}{8.716} & \multicolumn{1}{c}{6.260} & \multicolumn{1}{c}{0.676} & \multicolumn{1}{c}{4.827} & \multicolumn{1}{c}{2.273} & \multicolumn{1}{c}{1.948} \\     
    & \multicolumn{1}{c}{df = 8; 1728} & \multicolumn{1}{c}{df = 9; 1727} & \multicolumn{1}{c}{df = 7; 500} & \multicolumn{1}{c}{df = 10; 159} & \multicolumn{1}{c}{df = 6; 33} & \multicolumn{1}{c}{df = 3; 340} & \multicolumn{1}{c}{df = 6; 102} & \multicolumn{1}{c}{df = 7; 30} \\ 
\bottomrule
\insertTableNotes\\
    \end{longtable}
    \end{ThreePartTable} 
\end{landscape}
\end{document}