【问题标题】:Create table with subscripts and coloured rows using Bookdown使用 Bookdown 创建带有下标和彩色行的表格
【发布时间】:2018-06-06 01:43:08
【问题描述】:

我正在尝试从包含复杂表格的 Bookdown 脚本生成 PDF。该表包括一些带有下标的参数名称。我还想为一些行着色。示例脚本如下所示:

---
title: "Example problem"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
  #bookdown::gitbook: default
  bookdown::pdf_book: default
always_allow_html: yes  
---
This is a test example for the problem.

```{r}
library(magrittr)
library(knitr)
library(kableExtra)
df <- data.frame(Parameter = c("NO~x~ emissions", "SO~2~ emissions", "CO~2~     emissions"), "Value mg/Nm^3^" = c(800,900,1000),check.names=F)

knitr::kable(df,escape = F, caption = 'Example table!',  booktabs = TRUE, format = "latex") %>% #
  row_spec(0, bold = T, color = "white", background = "#045a8d") %>%
  row_spec(c(2), bold = T, color = "white", background = "#3690c0")
```
blah blah

我可以使用 kable 格式作为 'format = "html"' 运行脚本,结果看起来很好,包括彩色行和下标。当我将格式更改为 Latex 时,下标在生成的 pdf 中显示不正确。

我尝试将参数 escape = F 添加到 kable,但构建过程失败。

Quitting from lines 14-23 (_main.Rmd) 
Error in kable_latex(x = c("$NO_{x}$ emissions", "SO2 emissions", "CO2 emissions",  : 
  unused argument (example = FALSE)
Calls: <Anonymous> ... eval -> %>% -> eval -> eval -> <Anonymous> -> do.call

谁能帮忙解决这个问题?

【问题讨论】:

    标签: r bookdown kable


    【解决方案1】:

    对我来说,如果我使用(转义)LaTeX 语法,它就可以工作:

    ---
    title: "Example problem"
    author: "Frida Gomam"
    site: bookdown::bookdown_site
    documentclass: book
    output:
      bookdown::pdf_book: default
      #bookdown::gitbook: default
    always_allow_html: yes  
    ---
    This is a test example for the problem.
    
    ```{r}
    library(magrittr)
    library(knitr)
    library(kableExtra)
    df <- data.frame(Parameter = c("NO\\textsubscript{x} emissions", "SO\\textsubscript{2} emissions", "CO\\textsubscript{2}     emissions"),
                     "Value mg/Nm\\textsuperscript{3}" = c(800,900,1000),
                     check.names = F)
    
    knitr::kable(df,escape = F, caption = 'Example table!',  booktabs = TRUE, format = "latex") %>% #
      row_spec(0, bold = T, color = "white", background = "#045a8d") %>%
      row_spec(c(2), bold = T, color = "white", background = "#3690c0")
    ```
    blah blah
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-10
      • 2021-07-02
      • 1970-01-01
      • 2019-04-22
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多