Problem:
Regression tables need to be shrunk to include in Beamer slides, but cannot shrink them in RMarkdown without copy and pasting the raw TeX. Is there an easier way to do this so I can automate this part of my workflow?
Background
My regressions automatically generate .tex files for regression tables. However, when I try to input the files into my Beamer slides (created in Rmarkdown), they are too big and I have to manually copy, paste, and resize them to make them fit. Below is an MWE
table.tex
\begin{table}[!htbp] \centering
\caption{Title}
\begin{tabular}{lcccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& \multicolumn{6}{c}{Dependent Var} \\
\hline \\[-1.8ex]
Independent Var & $-$0.031 & 0.012 & $-$0.264 & $-$0.267 & $-$0.107 & $-$1.980 \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{6}{l}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
RMarkdown.Rmd
---
title: "Title"
output:
beamer_presentation:
slide_level: 3
keep_tex: false
---
### Test Results
\input{table.tex}
Workaround
Copy/paste .tex table and add \resizebox{}{}
surrounding \begin{tabular}...\end{tabular}
Workaround.Rmd
---
title: "Title"
output:
beamer_presentation:
slide_level: 3
keep_tex: false
---
### Test Results
\begin{table}[!htbp] \centering
\caption{Title}
\resizebox{0.98\textwidth}{!}{
\begin{tabular}{lcccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& \multicolumn{6}{c}{Dependent Var} \\
\hline \\[-1.8ex]
Independent Var & $-$0.031 & 0.012 & $-$0.264 & $-$0.267 & $-$0.107 & $-$1.980 \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{6}{l}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
}
\end{table}
Scaling elements which contain text can result in a sub-optimal readability of the text. Instead you could use the fitting
library from the tcolorbox
package to automatically choose a suitable font size:
---
title: "Title"
output:
beamer_presentation:
slide_level: 3
keep_tex: false
header-includes:
- \usepackage{tcolorbox}
- \tcbuselibrary{fitting}
---
### Test Results
\begin{tcolorbox}[fit,width=\textwidth,height=.9\textheight,size=minimal,colback=white,fit algorithm=fontsize,colframe=white]
\input{table.tex}
\end{tcolorbox}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With