HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Markdown PDF and stargazer resizing table #85

Open bjoernboening opened 8 years ago

bjoernboening commented 8 years ago

Might be a little late, but nevertheless is driving me nuts.

Whenever I add a stargazer regression table to the markdown (knit as pdf), I only get one long column.

Is there a way to fit the table to the page?

Several forums suggest, that this issue remains untackled by the developers, might this be true, or did someone find a solution?

Thanks in advance.

LarsMehwald commented 8 years ago

Dear Björn, I dont have a solution, but an idea - in case you know how to do it with LaTeX (which I dont): You can save the LaTeX output of stargazer and manually manipulate it (with LaTeX code that does what you want). The code is explained here: http://stackoverflow.com/questions/33543159/how-to-align-stargazer-table-to-the-left-when-type-latex Hope that helps, Lars

christophergandrud commented 8 years ago

Is this related to having many variables in your model? If so you can omit certain variables from the table to focus on key ones using the omit argument to stargazer.

Mark-Bergn commented 7 years ago

I've had the same issue, best work around I found was to generate the stargazer output outside of Rmarkdown then copy and paste it into the markdown body and add the latex commands "\resizebox{\linewidth}{!}{ %% " and "} %resizebox" to fit the output to page.

i.e....

Example Stargazer Output:

\begin{table}[!htbp] \centering \caption{} \label{} \resizebox{\linewidth}{!}{ %% \begin{tabular}{@{\extracolsep{5pt}}lc} \[-1.8ex]\hline \hline \[-1.8ex] & \multicolumn{1}{c}{\textit{Dependent variable:}} \ \cline{2-2} \[-1.8ex] & y \ \hline \[-1.8ex] x & $-$1.587 \ & (2.701) \ & \ Constant & 50.500$^{}$ \ & (2.911) \ & \ \hline \[-1.8ex] Observations & 100 \ \hline \hline \[-1.8ex] \textit{Note:} & \multicolumn{1}{r}{$^{}$p$<$0.1; $^{}$p$<$0.05; $^{*}$p$<$0.01} \ \end{tabular} } %resizebox** \end{table}

This solution comes from- https://stackoverflow.com/questions/16507191/automatically-adjust-latex-table-width-to-fit-pdf-using-knitr-and-rstudio