问题
Every time I add align=TRUE the document won't knit. I would like to align each column's coefficients so that their decimals are directly above/below each other.
Here is my "chunk code"
```{r, results="asis", echo="FALSE", eval="TRUE"}
library(stargazer)
stargazer(model1, model2, model3, type = "latex",
title = "Country Deaths from Political Violence in 1975",
dep.var.labels.include = FALSE, dep.var.caption = "Deaths",
digits = 1, header = FALSE,
covariate.labels = c("Intercept", "Sanctions", "Political Rights",
"Upper 20 percent income share",
"Interaction of Political Rights and Sanctions"))
```
回答1:
The tex tables produced with align=TRUE
begin with
\begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} }
Applying gsub
on stargazer and replacing the dots with \\cdot
. Then using cat
, solved the problem for me.
MWE:
table<-stargazer(example, align=TRUE)
tablenew<-gsub("D{.}{.}{-3} ","D.{\\cdot}{-3}",table,fixed=TRUE)
<<label, eval=TRUE, echo=FALSE, results='asis', warning=FALSE, message=FALSE>>=
knitrout<-cat(tablenwe, sep="\n")
@
One drawback is that \cdot
is too high.
来源:https://stackoverflow.com/questions/42034213/how-to-align-coefficients-using-stargazer-in-r-markdown