【问题标题】:kableExtra linebreak cannot produce line breakskableExtra linebreak 不能产生换行符
【发布时间】:2021-02-28 15:41:12
【问题描述】:

我想在表格中执行换行符,如this document of Best Practice for newline in LaTeX table 所述。但是,有些东西不起作用,我不知道为什么。我认为这是由于字符串长度或其他原因。

这是我最小的可重现示例。如果我尝试在带有 PDF(和 Html,在kable() 中将"latex" 替换为"html")输出的markdown 文档中编写它,它会崩溃。

library(dplyr, warn.conflicts = F)
library(kableExtra)

dd <- structure(
  list(data_source = seq(1:10), 
       data = c("53 records \nx 9 values \n= 477 data points", 
                "618019 records \nx 11 values \n= 6798209 data points", "4639 records \nx 22 values \n= 102058 data points", 
                "24691 records \nx 50 values \n= 1234550 data points", "30 records \nx 8 values \n= 240 data points", 
                "42 records \nx 
                3 values \n= 126 data points", "963 records \nx 2 values \n= 1926 data points", 
                "56295 records \nx 4 values \n= 225180 data points", "12 records \nx 5 values \n= 60 data points", 
                "8362826 data points (704744 records)")), 
  row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame")
)

dd %>% 
  mutate_all(linebreak) %>% 
  kable("latex", booktabs = T, escape = F)

错误如下。我已经尝试了debugging tips,但没有得到任何有关该错误的更多有用信息。

! Missing $ inserted.
<inserted text> 
                $
l.163 data_
           source & data\\ 

Try to find the following text in Untitled.Rmd:
  data_ 

You may need to add $ $ around a certain inline R expression `r ` in Untitled.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.
Execution halted

有什么想法吗?

【问题讨论】:

    标签: r r-markdown knitr kableextra


    【解决方案1】:

    下划线是 LaTeX 中的一个特殊数学字符。既然你要求kable 不要转义它(我假设变量F 的值是FALSE),你需要自己转义它,或者重命名第一列不带下划线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多