I'm trying to add a fairly long note to the bottom of a table created by texreg
; I want this to simply wrap around, but there doesn't seem to be any functionality built into the function for doing so.
Take, e.g.:
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 compiled, gives something like:
The formatting is atrocious; much better would be something like replacing the 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 wrapping:
\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 output much closer to what I'm looking for:
Is there a way to do this programatically?
With version 1.37.1 (released in May 2020),
texreg
introduces thethreeparttable
argument, which uses thethreeparttable
LaTeX package, which was designed for this purpose.Example R code:
Output:
Which is rendered as:
Note that the custom note must start with
\\item
. It is also possible to have multiple items and/or use bullet points to format multiple notes like in a list:The formatting is not perfect as you cannot set the desired width of the table; the note just adjusts to the width of the respective table. But I think it should be less of a problem in a realistic usage scenario where more than one model is displayed at a time and some of the coefficient names are longer than in the example. This solution also supports
longtable
environments, in which case thethreeparttablex
package is used instead.Here is an example of how you could make it look nice with two models:
This yields:
Which renders as: