如何更改RMarkdown PDF中kableExtra()的文本颜色-脚注?

如何更改RMarkdown PDF中kableExtra()的文本颜色-脚注?,r,r-markdown,kableextra,R,R Markdown,Kableextra,我正在用kableExtra中的表创建一个Rmarkdown PDF报告。有没有办法根据cell_spec中设置的条件格式更改脚注的文本颜色 我尝试使用paste0,请参阅下面kableExtra提供的最小reprex。我无法更改PDF输出,请求是针对客户端的 Im运行R版本3.5.1 2018-07-02,平台:x86_64-apple-darwin15.6.0 64位,在macOS 10.14.2和kableExtra_0.9.0下运行 --- title: "Minimal Reprex"

我正在用kableExtra中的表创建一个Rmarkdown PDF报告。有没有办法根据cell_spec中设置的条件格式更改脚注的文本颜色

我尝试使用paste0,请参阅下面kableExtra提供的最小reprex。我无法更改PDF输出,请求是针对客户端的

Im运行R版本3.5.1 2018-07-02,平台:x86_64-apple-darwin15.6.0 64位,在macOS 10.14.2和kableExtra_0.9.0下运行

---
title: "Minimal Reprex"
output: pdf_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = TRUE)

# packages
library(dplyr)
library(kableExtra)
```


```{r reprex}
mtcars[1:10, 1:2] %>%
   mutate(
    car = row.names(.),
    # You don't need format = "latex" if you have ever defined 
      options(knitr.table.format)
    mpg = cell_spec(mpg, "latex", color = ifelse(mpg > 20, "red", 
     "black")),
    cyl = cell_spec(cyl, "latex", color = "white", align = "c", 
     angle = 45,
    background = factor(cyl, c(4, 6, 8),
    c("#666666", "#999999", "#BBBBBB")))) %>%
    select(car, mpg, cyl) %>%
    kable("latex", escape = F, booktabs = T, linesep = "") %>% 
    footnote(paste0("MPG > 20 is displayed in", "\textcolor{red} 
    {red}"))

  ```

我希望单词red被涂成红色,当我得到\textcolor{red}{red}-它只是粘贴这个文本。我知道粘贴latex代码有问题,但我无法解决。

使用四个反斜杠和escape=F选项:

如果不使用escape=F,对像\&%{}这样具有特殊含义的字符将被转义,结果是输出文档中有字符本身。 在这里,我们手动转义生成的tex文档中的反斜杠将只有一个

footnote("MPG > 20 is displayed in \\\\textcolor{red}{red}", escape = F)