Stargazer column on multiple lines *with multiple models*?

♀尐吖头ヾ 提交于 2021-01-24 15:03:23

问题


Similar question as Getting Stargazer Column labels to print on two or three lines?.

I have long model titles that I would like to print on several lines while showing the results for multiple models.

Unfortunately, the answer to the other question does not work in this case.

var1<-rnorm(100)
var2<-rnorm(100)
df<-data.frame(var1, var2)
mod<-lm(var1~var2)
library(stargazer)
stargazer(mod, mod, column.labels=c('my models\\\\ & need long titles', 
                                    'my models\\\\ & need long titles'))

yields

Obviously, I would like for each title to remain in its column (as if it was included in an \mbox or something).

I've tried several variants of

var1<-rnorm(100)
var2<-rnorm(100)
df<-data.frame(var1, var2)
mod<-lm(var1~var2)
library(stargazer)
stargazer(mod, mod, column.labels=c('\\mbox\{my models\\\\ & need long titles\}', 
                                    '\\mbox\{my models\\\\ & need long titles\}'))

but I always get errors. I am not quite sure how to properly escape the \mbox command so it's properly read by latex, or whether that would even work.


回答1:


Ok, my apologies, I was really close, I should have looked a little harder before posting. The key was 1) to use \shortstack instead of \mbox and 2) not to escape the { characters.

var1<-rnorm(100)
var2<-rnorm(100)
df<-data.frame(var1, var2)
mod<-lm(var1~var2)
library(stargazer)
stargazer(mod, mod, column.labels=c('\\shortstack{my models \\\\ need long titles}', 
                                    '\\shortstack{my models \\\\ need long titles}'))



来源:https://stackoverflow.com/questions/58772564/stargazer-column-on-multiple-lines-with-multiple-models

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