【发布时间】:2020-12-14 20:47:18
【问题描述】:
我正在尝试使用 bookdown 将 .bib 文件中的引文包含到 Rmarkdown 中的 kable 表中。如果我使用 kableExtra::kbl() 在 kable 中指定 format = "markdown",则引用有效。但是将此提供给其他 kable_styling 格式化选项不再起作用并导致警告:
---
title: "Citation in landscape table"
site: bookdown::bookdown_site
output:
bookdown::pdf_book:
bibliography: [ref.bib]
biblio-style: apalike
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library('kableExtra')
```
```{r}
tmp <- data.frame('line' = c(1:3), 'ref' = c("no ref", "@R-base", "no ref"))
kbl(tmp, format = "markdown", longtable = TRUE, booktabs = TRUE, escape = FALSE) %>%
kable_styling(latex_options =c("striped", "hold_position", "repeat_header", "scale_down")) %>%
column_spec(2, width = "20em") %>%
landscape()
```
这会导致生成的 pdf 中出现警告消息:
## Warning in kableExtra::kable_styling(., latex_options = c("striped",
## "hold_position", : Please specify format in kable. kableExtra can customize
## either HTML or LaTeX outputs. See https://haozhu233.github.io/kableExtra/ for
## details.
## Warning in column_spec(., 2, width = "20em"): Please specify format in
## kable. kableExtra can customize either HTML or LaTeX outputs. See https://
## haozhu233.github.io/kableExtra/ for details.
## Warning in kableExtra::landscape(.): Please specify format in kable. kableExtra
## can customize either HTML or LaTeX outputs. See https://haozhu233.github.io/
## kableExtra/ for details
如果我排除 format = "markdown" 选项,警告会消失,我会得到正确的横向表格,但引用不再起作用。
如何获得带有kable_styling() 指定选项的横向表格和表格中的工作引用?
ref.bib的内容是:
@Manual{R-base,
title = {R: A Language and Environment for Statistical
Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2019},
url = {https://www.R-project.org},
}
【问题讨论】:
标签: r r-markdown bookdown kable citations