3

I am facing an overfull problem with my table, and, as I'm a beginner in latex, I'd need a hand. Here is the table:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\graphicspath{ {./images/} }
\usepackage{titling}
\usepackage{blindtext}

    % Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
    % Date and time: sex, dez 13, 2019 - 18:16:21
    \begin{table}[!htbp] \centering 
      \caption{Quantile regression approach} 
      \label{} 
    \begin{tabular}{@{\extracolsep{5pt}}lcccccccccc} 
    \\[-1.8ex]\hline 
    \hline \\[-1.8ex] 
     & \multicolumn{10}{c}{\textit{Dependent variable:}} \\ 
    \cline{2-11} 
    \\[-1.8ex] & \multicolumn{10}{c}{School attendance} \\ 
    \\[-1.8ex] & \textit{OLS} & \multicolumn{9}{c}{\textit{quantile}} \\ 
     & \textit{} & \multicolumn{9}{c}{\textit{regression}} \\ 
     &  & Q10 & Q20 & Q30 & Q40 & Q50 & Q60 & Q70 & Q80 & Q90 \\ 
    \hline \\[-1.8ex] 
     Piped water and sewage & 0.071$^{***}$ & 0.101$^{***}$ & 0.073$^{***}$ & 0.069$^{***}$ & 0.060$^{***}$ & 0.052$^{***}$ & 0.031$^{***}$ & 0.019$^{***}$ & 0.002 & $-$0.001 \\ 
      & (0.006) & (0.020) & (0.008) & (0.010) & (0.007) & (0.008) & (0.009) & (0.006) & (0.003) & (0.003) \\ 
      & & & & & & & & & & \\ 
     Water & $-$0.055$^{***}$ & $-$0.057$^{**}$ & $-$0.038$^{***}$ & $-$0.048$^{***}$ & $-$0.047$^{***}$ & $-$0.045$^{***}$ & $-$0.026$^{***}$ & $-$0.017$^{**}$ & $-$0.0002 & 0.003 \\ 
      & (0.006) & (0.023) & (0.010) & (0.012) & (0.009) & (0.010) & (0.010) & (0.007) & (0.004) & (0.003) \\ 
      & & & & & & & & & & \\ 
     Illiteracy & 0.054$^{***}$ & 0.058$^{***}$ & 0.050$^{***}$ & 0.045$^{***}$ & 0.040$^{***}$ & 0.037$^{***}$ & 0.031$^{***}$ & 0.026$^{***}$ & 0.020$^{***}$ & 0.010$^{***}$ \\ 
      & (0.004) & (0.005) & (0.003) & (0.002) & (0.002) & (0.001) & (0.002) & (0.001) & (0.001) & (0.001) \\ 
      & & & & & & & & & & \\ 
     Gini & 1.611$^{***}$ & 1.820$^{***}$ & 1.557$^{***}$ & 1.409$^{***}$ & 1.252$^{***}$ & 1.134$^{***}$ & 0.978$^{***}$ & 0.850$^{***}$ & 0.689$^{***}$ & 0.490$^{***}$ \\ 
      & (0.023) & (0.060) & (0.033) & (0.028) & (0.024) & (0.023) & (0.021) & (0.019) & (0.018) & (0.013) \\ 
      & & & & & & & & & & \\ 
     Income per capita & $-$0.229$^{***}$ & $-$0.235$^{***}$ & $-$0.202$^{***}$ & $-$0.180$^{***}$ & $-$0.156$^{***}$ & $-$0.140$^{***}$ & $-$0.119$^{***}$ & $-$0.102$^{***}$ & $-$0.081$^{***}$ & $-$0.059$^{***}$ \\ 
      & (0.005) & (0.010) & (0.005) & (0.004) & (0.003) & (0.003) & (0.003) & (0.003) & (0.002) & (0.002) \\ 
      & & & & & & & & & & \\ 
     Population & 0.014$^{***}$ & 0.014$^{***}$ & 0.015$^{***}$ & 0.015$^{***}$ & 0.014$^{***}$ & 0.014$^{***}$ & 0.013$^{***}$ & 0.013$^{***}$ & 0.012$^{***}$ & 0.012$^{***}$ \\ 
      & (0.001) & (0.001) & (0.001) & (0.001) & (0.0005) & (0.0005) & (0.0004) & (0.0003) & (0.0002) & (0.0003) \\ 
      & & & & & & & & & & \\ 
     Health and sanitation & 0.008$^{***}$ & 0.001 & 0.001 & 0.003$^{**}$ & 0.004$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.005$^{***}$ & 0.005$^{***}$ \\ 
      & (0.002) & (0.002) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.0005) & (0.001) \\ 
      & & & & & & & & & & \\ 
     Education and culture & 0.004$^{**}$ & 0.010$^{***}$ & 0.010$^{***}$ & 0.009$^{***}$ & 0.008$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.005$^{***}$ \\ 
      & (0.002) & (0.002) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.0005) & (0.001) \\ 
      & & & & & & & & & & \\ 
     Constant & 2.549$^{***}$ & 2.503$^{***}$ & 2.424$^{***}$ & 2.391$^{***}$ & 2.346$^{***}$ & 2.313$^{***}$ & 2.261$^{***}$ & 2.220$^{***}$ & 2.167$^{***}$ & 2.109$^{***}$ \\ 
      & (0.017) & (0.033) & (0.018) & (0.013) & (0.012) & (0.011) & (0.011) & (0.009) & (0.007) & (0.005) \\ 
      & & & & & & & & & & \\ 
    \hline \\[-1.8ex] 
    Observations & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 \\ 
    R$^{2}$ & 0.780 &  &  &  &  &  &  &  &  &  \\ 
    Adjusted R$^{2}$ & 0.780 &  &  &  &  &  &  &  &  &  \\ 
    Residual Std. Error & 0.041 (df = 8131) &  &  &  &  &  &  &  &  &  \\ 
    F Statistic & 3,604.162$^{***}$ (df = 8; 8131) &  &  &  &  &  &  &  &  &  \\ 
    \hline 
    \hline \\[-1.8ex] 
    \textit{Note:}  & \multicolumn{10}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
    \end{tabular}
    \end{table}

\end{document}

I need all the information that is in the table, including the ***.

  • Could you please make your example code compilable by adding the documentclass you use as well as the relevant packages? – leandriis Dec 14 '19 at 16:03
  • Since your table seems to be very wide, did you already consider rotating ot to a landscape orientation? Reducing the font size as well as the value of \tabcolssp might also help. – leandriis Dec 14 '19 at 16:04
  • @leandriis, I have edited the code, take a look. How can I rotate? – Mateus Maciel Dec 14 '19 at 16:08
  • you can rotate the table with the help of the landscape environment of for example the pdflscape package. – leandriis Dec 14 '19 at 16:11
  • 1
    Please check it compiles. You need \begin{document}. You can use sidewaystable from the rotating package. – cfr Dec 14 '19 at 16:13
6

With the help of the landscape environment, a slightly smaller \tabcolsep and \addlinespace from the booktabs package instead of the empty lines, you can achieve the following result.

Personally, I would also prefer the horizontal lines from the booktabs package over the \hlines. If you wish to additionally improve the alignment of the numbers inside of theeir olumns, you might be interested in the siunitx package and its S type column.

enter image description here

\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{pdflscape}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}


\begin{landscape}
\begin{table}[!htbp] \centering \setlength{\tabcolsep}{3.9pt}
  \caption{Quantile regression approach} 
  \label{} 
\begin{tabular}{lcccccccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{10}{c}{\textit{Dependent variable:}} \\ 
\cline{2-11} 
\\[-1.8ex] & \multicolumn{10}{c}{School attendance} \\ 
\\[-1.8ex] & \textit{OLS} & \multicolumn{9}{c}{\textit{quantile}} \\ 
 & \textit{} & \multicolumn{9}{c}{\textit{regression}} \\ 
 &  & Q10 & Q20 & Q30 & Q40 & Q50 & Q60 & Q70 & Q80 & Q90 \\ 
\hline \\[-1.8ex] 
 Piped water and sewage & 0.071$^{***}$ & 0.101$^{***}$ & 0.073$^{***}$ & 0.069$^{***}$ & 0.060$^{***}$ & 0.052$^{***}$ & 0.031$^{***}$ & 0.019$^{***}$ & 0.002 & $-$0.001 \\ 
  & (0.006) & (0.020) & (0.008) & (0.010) & (0.007) & (0.008) & (0.009) & (0.006) & (0.003) & (0.003) \\ 
\addlinespace
 Water & $-$0.055$^{***}$ & $-$0.057$^{**}$ & $-$0.038$^{***}$ & $-$0.048$^{***}$ & $-$0.047$^{***}$ & $-$0.045$^{***}$ & $-$0.026$^{***}$ & $-$0.017$^{**}$ & $-$0.0002 & 0.003 \\ 
  & (0.006) & (0.023) & (0.010) & (0.012) & (0.009) & (0.010) & (0.010) & (0.007) & (0.004) & (0.003) \\ 
\addlinespace
 Illiteracy & 0.054$^{***}$ & 0.058$^{***}$ & 0.050$^{***}$ & 0.045$^{***}$ & 0.040$^{***}$ & 0.037$^{***}$ & 0.031$^{***}$ & 0.026$^{***}$ & 0.020$^{***}$ & 0.010$^{***}$ \\ 
  & (0.004) & (0.005) & (0.003) & (0.002) & (0.002) & (0.001) & (0.002) & (0.001) & (0.001) & (0.001) \\ 
\addlinespace
 Gini & 1.611$^{***}$ & 1.820$^{***}$ & 1.557$^{***}$ & 1.409$^{***}$ & 1.252$^{***}$ & 1.134$^{***}$ & 0.978$^{***}$ & 0.850$^{***}$ & 0.689$^{***}$ & 0.490$^{***}$ \\ 
  & (0.023) & (0.060) & (0.033) & (0.028) & (0.024) & (0.023) & (0.021) & (0.019) & (0.018) & (0.013) \\ 
\addlinespace
 Income per capita & $-$0.229$^{***}$ & $-$0.235$^{***}$ & $-$0.202$^{***}$ & $-$0.180$^{***}$ & $-$0.156$^{***}$ & $-$0.140$^{***}$ & $-$0.119$^{***}$ & $-$0.102$^{***}$ & $-$0.081$^{***}$ & $-$0.059$^{***}$ \\ 
  & (0.005) & (0.010) & (0.005) & (0.004) & (0.003) & (0.003) & (0.003) & (0.003) & (0.002) & (0.002) \\ 
\addlinespace
 Population & 0.014$^{***}$ & 0.014$^{***}$ & 0.015$^{***}$ & 0.015$^{***}$ & 0.014$^{***}$ & 0.014$^{***}$ & 0.013$^{***}$ & 0.013$^{***}$ & 0.012$^{***}$ & 0.012$^{***}$ \\ 
  & (0.001) & (0.001) & (0.001) & (0.001) & (0.0005) & (0.0005) & (0.0004) & (0.0003) & (0.0002) & (0.0003) \\ 
\addlinespace 
 Health and sanitation & 0.008$^{***}$ & 0.001 & 0.001 & 0.003$^{**}$ & 0.004$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.005$^{***}$ & 0.005$^{***}$ \\ 
  & (0.002) & (0.002) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.0005) & (0.001) \\ 
\addlinespace 
 Education and culture & 0.004$^{**}$ & 0.010$^{***}$ & 0.010$^{***}$ & 0.009$^{***}$ & 0.008$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.006$^{***}$ & 0.005$^{***}$ \\ 
  & (0.002) & (0.002) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.001) & (0.0005) & (0.001) \\ 
\addlinespace 
 Constant & 2.549$^{***}$ & 2.503$^{***}$ & 2.424$^{***}$ & 2.391$^{***}$ & 2.346$^{***}$ & 2.313$^{***}$ & 2.261$^{***}$ & 2.220$^{***}$ & 2.167$^{***}$ & 2.109$^{***}$ \\ 
  & (0.017) & (0.033) & (0.018) & (0.013) & (0.012) & (0.011) & (0.011) & (0.009) & (0.007) & (0.005) \\ 
\addlinespace
\hline \\[-1.8ex] 
Observations & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 & 8,140 \\ 
R$^{2}$ & 0.780 &  &  &  &  &  &  &  &  &  \\ 
Adjusted R$^{2}$ & 0.780 &  &  &  &  &  &  &  &  &  \\ 
Residual Std. Error & 0.041 (df = 8131) &  &  &  &  &  &  &  &  &  \\ 
F Statistic & 3,604.162$^{***}$ (df = 8; 8131) &  &  &  &  &  &  &  &  &  \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{10}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular}
\end{table}
\end{landscape}
\end{document}
  • 1
    You really helped me, @leandriis! Thanks. – Mateus Maciel Dec 14 '19 at 16:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.