0

I have a texreg (Latex table) that won't fit on one page. How to fit in in single page?

library(tidyverse)
library(texreg)

d <- mtcars %>% mutate_at(.vars=c('vs','am','gear','carb'), .funs=factor)

lm <- lm(hp~am*gear*carb*mpg*hp,data=d)

texreg(lm,file='texfile.tex',return.string=F) 
Samuel Saari
  • 1,023
  • 8
  • 13

1 Answers1

0

A workaoround inspired by this great answer:

In the beginning of the Latex-document, write \usepackage{adjustbox}. Thereafter, change the texreg output as follows:

tr <- texreg(lm,return.string=T)

tr <- gsub("\\begin{tabular}"
           ,"\\begin{adjustbox}{totalheight=\\textheight-2\\baselineskip}\n\\begin{tabular}"
           ,tr
           ,fixed=T)

tr <- gsub("\\end{tabular}"
           ,"\\end{tabular}\n\\end{adjustbox}"
           ,tr
           ,fixed=T)

write_file(tr, 'test.tex')

Now when you write \input{test.tex} in your Latex-file, the output table will be squeezed to fit one page.

Samuel Saari
  • 1,023
  • 8
  • 13