问题
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