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

北城余情 提交于 2020-01-23 07:11:20

问题


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\nneed long titles')

Thanks.


回答1:


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')

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] 




回答2:


For multi-line column labels in html, the word you are looking for is:

<br>

For example, I have r-code that reads a CSV, modifies the labels with line breaks, and writes out as html like this:

filename <- "table1.csv"
pubTable <- read.table(file=filename,header = TRUE, sep = ",")
labels = c("Period", "2D and 3D <br>Image <br>Analysis"," Document <br>Processing"," 
Biometric <br>Identification ","Image <br>Databases","Video <br>Analysis","Biomedical 
<br>and <br>Biological")

library(stargazer)
stargazer(pubTable[],type = "html", rownames = FALSE, 
summary=FALSE,out="Table1.html",covariate.labels = labels)

The resulting table looks like this 1:

1 Adopted from Conte, Donatello, et al. "Thirty years of graph matching in pattern recognition." International journal of pattern recognition and artificial intelligence 18.03 (2004): 265-298.



来源:https://stackoverflow.com/questions/49138023/getting-stargazer-column-labels-to-print-on-two-or-three-lines

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