Wrapping custom notes in texreg output

那年仲夏 提交于 2019-12-01 05:50:59

I might point out a neat alternative solution I received which could be of interest to you, at the latest when you need to update the texreg package.

Accordingly the custom note ends in a \multicolumn in the LaTeX code, thus we cannot use line break commands like par or \\. But we can achieve the automatic line break with \parbox. If we still want a custom line break we can use four backslashes \\\\. For better formatting we can use \\vspace{2pt} just 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.}"))

I've come up with a workaround so far by rewriting the texreg function by adding a 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 pick a maximum string length for each line (custom.note.wrap) and then split the supplied note into strings of at most that length which end in a space, finally concatenating everything into a bunch of multicolumns with each split substring.

This is not optimal, as it would be better for texreg (to have the ability) to automatically set custom.note.wrap given the lengths of the model names, etc. But my raw LaTeX abilities are lacking, so I'm not sure how I would do this.

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