Welcome to OStack Knowledge Sharing 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...