【问题标题】:R kable formatted with kableExtra::cell_spec() gives verbatim latex-commands instead of expected format使用 kableExtra::cell_spec() 格式化的 R kable 给出了逐字的乳胶命令而不是预期的格式
【发布时间】:2022-12-17 01:40:16
【问题描述】:

问题

  • 使用 RStudio 的 R Markdown
  • 编织成PDF
  • 使用 kableExtra::cell_spec() 格式化的 kable 给出了逐字的乳胶命令而不是预期的格式

问题

  • 是否可以在其他环境中重现?
  • 有什么解决方案吗?

RMD 命令

---
title: "MWE cell_spec latex"
author: "Thomas"
date: "2022-12-16"
output: 
 pdf_document:
   keep_tex: yes

---

```{r setup, include=TRUE }


library("tidyverse")
library("kableExtra")

data <- data.frame(item=c("I'm red", "What color am I?"))

kable(data)

data %>%
  mutate(item = cell_spec(item, "latex",color = "red"))%>%
  kable()


```

表格环境中的 Tex 文件

tex 文件显示,pandoc 为单元格规范输出 \textbackslash{} 而不是 \

\begin{逐字}

\begin{表格} {l} \h线 物品\ \h线 \textbackslash{}textcolor{red}{I'm red}\ \h线 \textbackslash{}textcolor{red}{我是什么颜色?}\ \h线 \结束{表格}

\结束{逐字}

【问题讨论】:

    标签: r pdf latex kableextra


    【解决方案1】:

    你快到了。尝试:

    data  |> 
      mutate(item = cell_spec(item, "latex", color = "red")) |> 
      kable(escape = FALSE)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多