Combining user notes into texreg output

I am trying to add a rather long note at the bottom of the table created by texreg ; I want this to just wrap around, but there are no built-in functions for this function.

Take for example:

 texreg(lm(speed~dist,data=cars), custom.note=paste("%stars. This regression should be", "intepreted with strong caution as", "it is likely plagued by extensive", "omitted variable bias")) 

Which when compiling gives something like:

simple texreg

Formatting is cruel; much better would be something like replacing standard output:

 \multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$. This regression should be intepreted with strong caution as it is likely plagued by extensive omitted variable bias}} 

With more digestible packaging:

 \multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$.}} \\ \multicolumn{2}{l}{\scriptsize{This regression should be intepreted with}} \\ \multicolumn{2}{l}{\scriptsize{strong caution as it is likely plagued by}} \\ \multicolumn{2}{l}{\scriptsize{extensive omitted variable bias}} 

Which gives the result much closer to what I'm looking for:

preferred output

Is there any way to do this programmatically?

+5
r latex texreg
source share
2 answers

I could point out a neat alternative solution that I got that might interest you at the latest when you need to update the texreg package.

Accordingly, the user note ends with \multicolumn in LaTeX code, so we cannot use line break commands such as par or \\ . But we can achieve automatic line break using \parbox . If we still need an individual line break, we can use four backslashes \\\\ . For better formatting, we can use \\vspace{2pt} only at the beginning of the text content:

 texreg(lm(speed ~ dist, data = cars), custom.note = ("\\parbox{.4\\linewidth}{\\vspace{2pt}%stars. \\\\ This regression should be intepreted with strong caution as it is likely plagued by extensive omitted variable bias.}")) 

enter image description here

+2
source share

I still came up with a workaround by rewriting the texreg function, adding the custom.note.wrap argument and changing:

 note <- paste0("\\multicolumn{", length(models) + 1, "}{l}{\\", notesize, "{", custom.note, "}}") note <- gsub("%stars", snote, note, perl = TRUE) 

To:

 if (custom.note.wrap){ note<-paste(paste0("\\multicolumn{", length(models) + 1L,"}{l}{\\",notesize,"{", strwrap(custom.note, width=custom.note.wrap), "}}"), collapse = " \\ \n") note <- gsub("%stars", snote, note, perl = TRUE) }else{ note <- paste0("\\multicolumn{", length(models) + 1L, "}{l}{\\", notesize, "{", custom.note, "}}") note <- gsub("%stars", snote, note, perl = TRUE) } 

The idea is to select the maximum string length for each string ( custom.note.wrap ), and then split the provided note into strings of no more than length that end in space, finally concatenating everything into a multicolumn string with each split substring.

This is not optimal, since it would be better to texreg (be able to) automatically set custom.note.wrap taking into account the lengths of model names, etc. But my raw LaTeX features are missing, so I'm not sure how to do this.

+2
source share

All Articles