使用 kableExtra 的脚注内联样式

Footnote inline styling with kableExtra

为什么以下内容适用于标题而不适用于脚注?我如何在页脚中做到这一点?

library(kableExtra)

mtcars[1:5,] %>%
kable(caption = "why this <span style='color: red;'>is red</span>") %>%
  footnote(general_title = "",
           general = "and this<span style='color: red;'>isn't?</span>")

默认情况下,escape 参数在 footnote 中设置为 TRUE。这意味着您尝试包含在脚注中的任何 html 都将是 html-escaped,因此它将呈现为字符串而不是被解释为实际 html.

幸运的是,您可以将其关闭:

library(kableExtra)

mtcars[1:5,] %>%
kable(caption = "why this <span style='color: red;'>is red</span>") %>%
  footnote(general_title = "",
           general = "and this<span style='color: red;'> is too?</span>", 
           escape = FALSE)