r - new font style for stargazer latex table when using knitr -
r - new font style for stargazer latex table when using knitr -
i want print latex table generated stargazer()
in monospaced font, , want in reproducible way knitr
(i.e., no manual latex coding). tried define environment called mymono
, wrap knitr chunk in environment via \begin{}
, \end{}
. not work; table prints in default font style.
\documentclass{article} \newenvironment{mymono}{\ttfamily}{\par} \begin{document} <<lm, echo=false>>= df <- data.frame(x=1:10, y=rnorm(10)) library(stargazer) lm1 <- lm(y ~ x ,data=df) @ % reproducible \begin{mymono} <<table_texstyle, echo=false, results='asis', message=false>>= stargazer(lm1, label="test") @ \end{mymono} \end{document}
i don't think there font setting in stargazer()
except font.size
.
# > sessioninfo() # r version 3.0.2 (2013-09-25) # platform: x86_64-apple-darwin10.8.0 (64-bit) # other attached packages: # [1] stargazer_5.1
even improve wrapping entire table{}
in new font style wrap tabular{}
caption remains default style. don't know if there way insert latex code stargazer()
output programmatically.
too long comment, here's start of answer. using model question:
\documentclass{article} \begin{document} <<lm, echo=false, message=false, include=false>>= df <- data.frame(x=1:10, y=rnorm(10)) library(stargazer) lm1 <- lm(y ~ x ,data=df) tabular_tt <- function(orig.table) { library(stringr) tabular.start <- which(str_detect(orig.table, "begin\\{tabular\\}")) tabular.end <- which(str_detect(orig.table, "end\\{tabular\\}")) new.table <- c(orig.table[1:(tabular.start - 1)], "\\texttt{", orig.table[tabular.start:tabular.end], "}", orig.table[(tabular.end + 1):length(orig.table)]) return(new.table) } @ <<print, results='asis', echo=false>>= cat(tabular_tt(capture.output(stargazer(lm1, label="test"))), sep="\n") @ \end{document}
you can adjust necessary. if you're having trouble, create sure target latex syntax right playing little toy table in latex only, maybe playing tex file generated when knit.
you may need create function cat(new.table, sep = "\n")
acquire output correctly knitr document.
r latex knitr stargazer
Comments
Post a Comment