代码之家  ›  专栏  ›  技术社区  ›  delcast

字幕长度加宽表,额外+乳胶

  •  0
  • delcast  · 技术社区  · 7 年前

    问题: 我的桌子是用 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)
    

    于2018年7月18日由 reprex package (第0.2.0版)。

    1 回复  |  直到 7 年前
        1
  •  3
  •   iod    7 年前

    你可以用 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个字符?