Markdown PDF中的神秘空白(kableExtra)

时间:2018-07-09 13:50:13

标签: r r-markdown kable kableextra

考虑此示例

---
title: "R Notebook"
output:
  pdf_document: default
---

Hello this is a nice test

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
options(knitr.table.format = "latex")

library(knitr)
library(kableExtra)
library(dplyr)
# needed 
kable(cars, "latex") %>% kable_styling(bootstrap_options = "striped")
```

here we go

```{r, results = "asis"}
for (threshold in c(20, 25)) {
  cat("\n\n\\pagebreak\n")
  x <- mtcars %>%
    filter(mpg < threshold) %>%
    mutate(disp = cell_spec(
    disp, "latex", color = "white", bold = T,
    background = spec_color(1:10, end = 0.9, option = "A")
  )) %>% 
    kable('latex',  booktabs = T, escape=F) %>%
    kable_styling(latex_options = c("striped", "hold_position"),
                full_width = T) %>% 
   column_spec(1, bold = T, color = "red") %>% 
    add_header_above(c(" ", "$\\\\beta$" = 10),  escape = F)
  cat(x)
}
```

我正在尝试使用此处how to use a for loop in rmarkdown?解释的技巧来使用pdf中kableExtra中的所有原始功率。

这是一个很好的示例,说明如何生成动态的rmarkdown文档,该文档在for循环中创建表。

确实不错,除了cell_specs渐变包含了一些神秘的空白...

有什么想法吗?

enter image description here

谢谢!

1 个答案:

答案 0 :(得分:1)

如果您想知道每5行的空白,那是因为booktabs=T。您还应该添加linesep=""来摆脱该空白。