在RStudio中,我尝试将rmarkdown与bookdown结合使用(主要是为了让能力人员参考表格和数字),并且在表格和标题中遇到格式问题。请考虑以下示例:
---
title: "Test"
knit: "bookdown::render_book"
output:
bookdown::pdf_book:
keep_tex: yes
link-citations: true
references:
- type: article-journal
id: WatsonCrick1953
author:
- family: Watson
given: J. D.
- family: Crick
given: F. H. C.
issued:
1953
title: 'Molecular structure of nucleic acids: a structure for deoxyribose
nucleic acid'
container-title: Nature
volume: 171
issue: 4356
page: 737-738
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
```
@WatsonCrick1953
```{r test-table, tidy=FALSE, echo = FALSE}
kable(
data.frame(
Citation = c("@WatsonCrick1953"),
Formatted.String = c("Some--Thing^2^")),
caption = "*Bold* in a caption;"#, booktabs = TRUE
)
```
这有多个问题:
另一个问题是,目前生产的乳胶不会产生对#ta; booktabs"包,可能需要正确使用" booktabs = TRUE"对kable的论证(直接来自booktabs文档,因此应该起作用)。
请告诉我如何实现我的目标...
荷兰Joh
答案 0 :(得分:1)
切换到pander
可以解决问题:
---
title: "Test"
knit: "bookdown::render_book"
output:
bookdown::pdf_book:
keep_tex: yes
link-citations: true
references:
- type: article-journal
id: WatsonCrick1953
author:
- family: Watson
given: J. D.
- family: Crick
given: F. H. C.
issued:
1953
title: 'Molecular structure of nucleic acids: a structure for deoxyribose nucleic acid'
container-title: Nature
volume: 171
issue: 4356
page: 737-738
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
library(pander)
```
@WatsonCrick1953
```{r test-table, tidy=FALSE, echo = FALSE}
pander(
data.frame(
Citation = c("@WatsonCrick1953"),
Formatted.String = c("Some--Thing^2^")),
caption = "*Not bold* in a caption; **bold** in a caption;",
style = "simple",
justify = "left"
)
```
答案 1 :(得分:0)
由于您正在编织为PDF,kable()
的输出将自动检测到这一点,并进行格式化以生成乳胶。
因此,您需要使用乳胶说明格式化文本。
试试这个:
答案 2 :(得分:0)
我很高兴找到这篇文章,虽然我无法复制Andrie的回答。我想通过修改标题,添加也可以使用pander
引用该表:caption = "(\\#tab:test-table) *Not bold* in a caption; **bold** in a caption;",
我修改了代码以生成文章pdf文档而不是书籍,这段代码适用于我:
---
title: "Test"
output:
bookdown::pdf_document2:
keep_tex: yes
link-citations: true
references:
- type: article-journal
id: WatsonCrick1953
author:
- family: Watson
given: J. D.
- family: Crick
given: F. H. C.
issued:
1953
title: 'Molecular structure of nucleic acids: a structure for deoxyribose nucleic acid'
container-title: Nature
volume: 171
issue: 4356
page: 737-738
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE)
library(pander)
```
@WatsonCrick1953 in Table \@ref(tab:test-table)
```{r test-table, tidy=FALSE, echo = FALSE}
pander(
data.frame(
Citation = c("@WatsonCrick1953"),
Formatted.String = c("Some--Thing^2^")),
caption = "(\\#tab:test-table) *Not bold* in a caption; **bold** in a caption;",
style = "simple",
justify = "left"
)
```