archingfork
archingfork

Reputation: 155

Large table in Latex gets cut off when outputting to PDF?

I haven't worked with much Latex syntax so I'm not quite sure what stylization changes I need to make here.

I have a large piece of Latex as such:

\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{center}
\begin{longtable}{|l|l|l|} \centering

\begin{tabular}{@{\extracolsep{5pt}}lcccccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
 & \multicolumn{8}{c}{\textit{Dependent variable:}} \\
\cline{2-9}
\\[-1.8ex] & \multicolumn{2}{c}{Female} & \multicolumn{4}{c}{NonWhite} & \multicolumn{2}{c}{Black.or.African.American} \\
\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8)\\
\hline \\[-1.8ex]
 factor(ELECTORAL\_TERM)2018 & 0.104$^{***}$ & 0.104$^{***}$ & $-$0.104$^{***}$ & $-$0.104$^{***}$ & $-$0.103$^{***}$ & $-$0.103$^{***}$ & $-$0.047$^{***}$ & $-$0.047$^{***}$ \\
  & (0.010) & (0.010) & (0.009) & (0.009) & (0.009) & (0.009) & (0.006) & (0.006) \\
  & & & & & & & & \\
 factor(ELECTORAL\_TERM)2019 & 0.129$^{***}$ & 0.128$^{***}$ & 0.088$^{***}$ & 0.088$^{***}$ & 0.092$^{***}$ & 0.092$^{***}$ & 0.063$^{***}$ & 0.063$^{***}$ \\
  & (0.011) & (0.011) & (0.009) & (0.010) & (0.009) & (0.009) & (0.007) & (0.007) \\
  & & & & & & & & \\
 WOMENS\_RIGHTS\_PROTEST & $-$0.016 & $-$0.025 &  &  &  &  &  &  \\
  & (0.018) & (0.019) &  &  &  &  &  &  \\
  & & & & & & & & \\
 WOMENS\_RIGHTS\_COUNTERPROTEST &  & 0.052 &  &  &  &  &  &  \\
  &  & (0.043) &  &  &  &  &  &  \\
  & & & & & & & & \\
 RACIAL\_PROTEST &  &  & 0.032$^{***}$ & 0.032$^{***}$ &  &  & 0.020$^{***}$ & 0.021$^{***}$ \\
  &  &  & (0.010) & (0.011) &  &  & (0.007) & (0.008) \\
  & & & & & & & & \\
 RACIAL\_COUNTERPROTEST &  &  &  & 0.001 &  &  &  & $-$0.007 \\
  &  &  &  & (0.039) &  &  &  & (0.028) \\
  & & & & & & & & \\
 OTHER\_IDENTITY\_PROTEST &  &  &  &  & 0.057 & 0.068 &  &  \\
  &  &  &  &  & (0.077) & (0.078) &  &  \\
  & & & & & & & & \\
 OTHER\_IDENTITY\_COUNTERPROTEST &  &  &  &  &  & $-$0.116 &  &  \\
  &  &  &  &  &  & (0.156) &  &  \\
  & & & & & & & & \\
 Republican.Party & 0.061$^{***}$ & 0.061$^{***}$ & 0.068$^{***}$ & 0.068$^{***}$ & 0.068$^{***}$ & 0.068$^{***}$ & 0.027$^{***}$ & 0.027$^{***}$ \\
  & (0.014) & (0.014) & (0.012) & (0.012) & (0.012) & (0.012) & (0.009) & (0.009) \\
  & & & & & & & & \\
 Democratic.Party & 0.386$^{***}$ & 0.386$^{***}$ & 0.162$^{***}$ & 0.162$^{***}$ & 0.162$^{***}$ & 0.162$^{***}$ & 0.083$^{***}$ & 0.083$^{***}$ \\
  & (0.016) & (0.016) & (0.014) & (0.014) & (0.014) & (0.014) & (0.010) & (0.010) \\
  & & & & & & & & \\
 CIT\_EST\_White & $-$0.002 & $-$0.002 & 0.001 & 0.001 & 0.001 & 0.001 & 0.0002 & 0.0002 \\
  & (0.002) & (0.002) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) \\
  & & & & & & & & \\
 CIT\_EST\_African\_American & 0.007$^{**}$ & 0.007$^{**}$ & 0.001 & 0.001 & 0.001 & 0.001 & 0.0005 & 0.0005 \\
  & (0.004) & (0.004) & (0.003) & (0.003) & (0.003) & (0.003) & (0.002) & (0.002) \\
  & & & & & & & & \\
 CIT\_EST\_NonWhite & 0.014 & 0.014 & $-$0.004 & $-$0.004 & $-$0.004 & $-$0.004 & $-$0.002 & $-$0.002 \\
  & (0.011) & (0.011) & (0.009) & (0.009) & (0.009) & (0.009) & (0.007) & (0.007) \\
  & & & & & & & & \\
 CVAP\_EST\_White & 0.007 & 0.007 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.001 & $-$0.001 \\
  & (0.004) & (0.004) & (0.004) & (0.004) & (0.004) & (0.004) & (0.003) & (0.003) \\
  & & & & & & & & \\
 CVAP\_EST\_African\_American & $-$0.007 & $-$0.007 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.001 & $-$0.001 \\
  & (0.006) & (0.006) & (0.005) & (0.005) & (0.005) & (0.005) & (0.004) & (0.004) \\
  & & & & & & & & \\
 CVAP\_EST\_NonWhite & $-$0.020 & $-$0.020 & 0.006 & 0.006 & 0.006 & 0.006 & 0.002 & 0.002 \\
  & (0.016) & (0.016) & (0.014) & (0.014) & (0.014) & (0.014) & (0.010) & (0.010) \\
  & & & & & & & & \\
 Constant & $-$23.099 & $-$23.099 & 5.245 & 5.245 & 5.244 & 5.241 & 1.899 & 1.898 \\
  & (14.561) & (14.561) & (12.598) & (12.599) & (12.608) & (12.609) & (8.972) & (8.972) \\
  & & & & & & & & \\
\hline \\[-1.8ex]
Observations & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 \\
R$^{2}$ & 0.778 & 0.778 & 0.660 & 0.660 & 0.659 & 0.659 & 0.664 & 0.664 \\
Adjusted R$^{2}$ & 0.654 & 0.654 & 0.468 & 0.468 & 0.468 & 0.468 & 0.476 & 0.476 \\
Residual Std. Error & 0.403 (df = 6145) & 0.403 (df = 6144) & 0.348 (df = 6145) & 0.348 (df = 6144) & 0.349 (df = 6145) & 0.349 (df = 6144) & 0.248 (df = 6145) & 0.248 (df = 6144) \\
F Statistic & 6.250$^{***}$ (df = 3448; 6145) & 6.249$^{***}$ (df = 3449; 6144) & 3.452$^{***}$ (df = 3448; 6145) & 3.450$^{***}$ (df = 3449; 6144) & 3.443$^{***}$ (df = 3448; 6145) & 3.442$^{***}$ (df = 3449; 6144) & 3.524$^{***}$ (df = 3448; 6145) & 3.523$^{***}$ (df = 3449; 6144) \\
\hline
\hline \\[-1.8ex]
\textit{Note:}  & \multicolumn{8}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{longtable} 
\end{center}
\end{document}

The outputted PDF, however, looks like this:

enter image description here

Where both the bottom and right side of the table are cut off. I tried using longtable as you can see, but that doesn't seem to do much. I'm not sure if I need to rotate the table, or shift the table right, or allow for extra pages, or what.

Upvotes: 3

Views: 4907

Answers (1)

A couple of ideas:

  • don't use a tabular inside the longtable. Longtable is meant to be used instead and not around a tabular

  • if your table is already too big to fit the page, don't make it even bigger by manual adding extracolsep

  • use the paper in landscape to get more space

  • reduce the margins

  • use fixed width columns to force line breaks to make the columns smaller

  • the variables names in the first columns are very long and latex won't be able to hyphenate them automatically. Define possible break points

  • place the df values in a new row to make the columns smaller

  • if this all does not help, use bigger paper or split the table in multiple tables with fewer columns


\documentclass{article}
\usepackage{longtable}

\usepackage[landscape,hmargin=0.5cm]{geometry}
\begin{document}
\begin{longtable}{p{4.6cm}*{8}{p{1.7cm}}}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
 & \multicolumn{8}{c}{\textit{Dependent variable:}} \\
\cline{2-9}
\\[-1.8ex] & \multicolumn{2}{c}{Female} & \multicolumn{4}{c}{NonWhite} & \multicolumn{2}{c}{Black.or.Afr.Am.} \\
\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8)\\
\hline \\[-1.8ex]
 factor(\-ELECTORAL\-\_TERM)2018 & 0.104$^{***}$ & 0.104$^{***}$ & $-$0.104$^{***}$ & $-$0.104$^{***}$ & $-$0.103$^{***}$ & $-$0.103$^{***}$ & $-$0.047$^{***}$ & $-$0.047$^{***}$ \\
  & (0.010) & (0.010) & (0.009) & (0.009) & (0.009) & (0.009) & (0.006) & (0.006) \\
  & & & & & & & & \\
 factor(\-ELECTORAL\-\_TERM)2019 & 0.129$^{***}$ & 0.128$^{***}$ & 0.088$^{***}$ & 0.088$^{***}$ & 0.092$^{***}$ & 0.092$^{***}$ & 0.063$^{***}$ & 0.063$^{***}$ \\
  & (0.011) & (0.011) & (0.009) & (0.010) & (0.009) & (0.009) & (0.007) & (0.007) \\
  & & & & & & & & \\
 WOMENS\-\_RIGHTS\-\_PROTEST & $-$0.016 & $-$0.025 &  &  &  &  &  &  \\
  & (0.018) & (0.019) &  &  &  &  &  &  \\
  & & & & & & & & \\
 WOMENS\-\_RIGHTS\-\_COUNTERPROTEST &  & 0.052 &  &  &  &  &  &  \\
  &  & (0.043) &  &  &  &  &  &  \\
  & & & & & & & & \\
 RACIAL\-\_PROTEST &  &  & 0.032$^{***}$ & 0.032$^{***}$ &  &  & 0.020$^{***}$ & 0.021$^{***}$ \\
  &  &  & (0.010) & (0.011) &  &  & (0.007) & (0.008) \\
  & & & & & & & & \\
 RACIAL\-\_COUNTERPROTEST &  &  &  & 0.001 &  &  &  & $-$0.007 \\
  &  &  &  & (0.039) &  &  &  & (0.028) \\
  & & & & & & & & \\
 OTHER\-\_IDENTITY\-\_PROTEST &  &  &  &  & 0.057 & 0.068 &  &  \\
  &  &  &  &  & (0.077) & (0.078) &  &  \\
  & & & & & & & & \\
 OTHER\-\_IDENTITY\-\_COUNTERPROTEST &  &  &  &  &  & $-$0.116 &  &  \\
  &  &  &  &  &  & (0.156) &  &  \\
  & & & & & & & & \\
 Republican.Party & 0.061$^{***}$ & 0.061$^{***}$ & 0.068$^{***}$ & 0.068$^{***}$ & 0.068$^{***}$ & 0.068$^{***}$ & 0.027$^{***}$ & 0.027$^{***}$ \\
  & (0.014) & (0.014) & (0.012) & (0.012) & (0.012) & (0.012) & (0.009) & (0.009) \\
  & & & & & & & & \\
 Democratic.Party & 0.386$^{***}$ & 0.386$^{***}$ & 0.162$^{***}$ & 0.162$^{***}$ & 0.162$^{***}$ & 0.162$^{***}$ & 0.083$^{***}$ & 0.083$^{***}$ \\
  & (0.016) & (0.016) & (0.014) & (0.014) & (0.014) & (0.014) & (0.010) & (0.010) \\
  & & & & & & & & \\
 CIT\-\_EST\-\_White & $-$0.002 & $-$0.002 & 0.001 & 0.001 & 0.001 & 0.001 & 0.0002 & 0.0002 \\
  & (0.002) & (0.002) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) \\
  & & & & & & & & \\
 CIT\-\_EST\-\_African\-\_American & 0.007$^{**}$ & 0.007$^{**}$ & 0.001 & 0.001 & 0.001 & 0.001 & 0.0005 & 0.0005 \\
  & (0.004) & (0.004) & (0.003) & (0.003) & (0.003) & (0.003) & (0.002) & (0.002) \\
  & & & & & & & & \\
 CIT\-\_EST\-\_NonWhite & 0.014 & 0.014 & $-$0.004 & $-$0.004 & $-$0.004 & $-$0.004 & $-$0.002 & $-$0.002 \\
  & (0.011) & (0.011) & (0.009) & (0.009) & (0.009) & (0.009) & (0.007) & (0.007) \\
  & & & & & & & & \\
 CVAP\-\_EST\-\_White & 0.007 & 0.007 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.001 & $-$0.001 \\
  & (0.004) & (0.004) & (0.004) & (0.004) & (0.004) & (0.004) & (0.003) & (0.003) \\
  & & & & & & & & \\
 CVAP\-\_EST\-\_African\-\_American & $-$0.007 & $-$0.007 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.002 & $-$0.001 & $-$0.001 \\
  & (0.006) & (0.006) & (0.005) & (0.005) & (0.005) & (0.005) & (0.004) & (0.004) \\
  & & & & & & & & \\
 CVAP\-\_EST\-\_NonWhite & $-$0.020 & $-$0.020 & 0.006 & 0.006 & 0.006 & 0.006 & 0.002 & 0.002 \\
  & (0.016) & (0.016) & (0.014) & (0.014) & (0.014) & (0.014) & (0.010) & (0.010) \\
  & & & & & & & & \\
 Constant & $-$23.099 & $-$23.099 & 5.245 & 5.245 & 5.244 & 5.241 & 1.899 & 1.898 \\
  & (14.561) & (14.561) & (12.598) & (12.599) & (12.608) & (12.609) & (8.972) & (8.972) \\
  & & & & & & & & \\
\hline \\[-1.8ex]
Observations & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 & 9,594 \\
R$^{2}$ & 0.778 & 0.778 & 0.660 & 0.660 & 0.659 & 0.659 & 0.664 & 0.664 \\
Adjusted R$^{2}$ & 0.654 & 0.654 & 0.468 & 0.468 & 0.468 & 0.468 & 0.476 & 0.476 \\
Residual Std. Error & 0.403  & 0.403  & 0.348  & 0.348  & 0.349  & 0.349  & 0.248  & 0.248  \\
df & xxx & xxx & xxx & xxx & xxx & xxx & xxx & xxx \\
F Statistic & 6.250$^{***}$  & 6.249$^{***}$  & 3.452$^{***}$ & 3.450$^{***}$  & 3.443$^{***}$  & 3.442$^{***}$  & 3.524$^{***}$ & 3.523$^{***}$  \\
df & xxx & xxx & xxx & xxx & xxx & xxx & xxx & xxx \\
\hline
\hline \\[-1.8ex]
\textit{Note:}  & \multicolumn{8}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{longtable} 
\end{document}

Upvotes: 1

Related Questions