How to align coefficients using stargazer in R Markdown?

对着背影说爱祢 提交于 2021-01-29 03:39:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!