Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

r - Getting Stargazer Column labels to print on two or three lines?

I have some models that have long titles to be fully explanatory. It would be helpful to have them print their descriptors or titles on two lines. This reads the line break character, but the resulting latex output doesn't recognize it.

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

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

One option: You can insert latex codes for newline (\) and table column alignment (&). Note that each needs to be "escaped" in R with another .

stargazer(mod, column.labels='my models\\ & need long titles')

enter image description here

Another way is to multirow. This could be easier for more complex tables with different length headings on each column. You will need to add usepackage{multirow} to your document preamble.

stargazer(mod, column.labels='\multirow{2}{4 cm}{my models need long titles}')

You will also need to post-edit the latex output from stargazer to insert some extra lines (using \) below the variable headings so that the rest of the table gets moved down also (as in the exceprt below):

& multirow{2}{4 cm}{my models need long titles} \ 
\  % note the extra line inserted here before the horizontal rule
hline \[-1.8ex] 

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...