字幕长度加宽表Kable Extra +乳胶

时间:2018-07-18 12:24:06

标签: r latex kableextra

问题:我使用精美的kableExtra程序包构建的表如下所示:

enter image description here

如果有必要将标题调整为表格的最小宽度,如何强制标题为多行而不是相反?

carbon_benefits%>%
  set_names(c("Year","Date","Canary","Total","Date","Canary","Total"))%>%
kable(
    caption = "\\label{tab:carbon_costs}Carbon sequestration values over time.",
    booktabs = T,
    escape = F,
    linesep= "") %>%
  kable_styling(latex_options = c("hold_position"))%>%
  add_header_above(c("","Lower"=3,"Higher"=3))%>%
  footnote(general=paste("Combining the totals for all years for both species yields a lower bound of ",round(sum(carbon_benefits$total_lower),digits=0)," and a higher bound of ",round(sum(carbon_benefits$total_upper),digits=0),".",sep = ""),
           footnote_as_chunk = T)

reprex package(v0.2.0)于2018-07-18创建。

1 个答案:

答案 0 :(得分:3)

您可以使用str_wrap包中的stringr将文本包装成合理的行长:

footnote(general=
  stringr::str_wrap(paste0("Combining the totals for all years for both species yields a lower bound of ",round(sum(carbon_benefits$total_lower),digits=0)," and a higher bound of ",round(sum(carbon_benefits$total_upper),digits=0),"."), 
    width=txtwidth), 
  footnote_as_chunk = T)
然后,可以根据预期的列数将

txtwidth设置为合理长度的计算。这取决于您的数据结构。在这种情况下,每列大约需要5-6个字符,所以35-40个字符?