1

在 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
)
```

所得产品的详细信息是: 在此处输入图像描述

这有多个问题:

  1. 标题中的“粗体”不是 rmarkdown 格式
  2. “^2^”不会产生预期的上标(特别奇怪,因为“--”被理解为破折号)
  3. 表格中无法理解引用(在文本中,表格代码上方,它工作得很好,但不包含在屏幕截图中)

另一个问题是当前生产的乳胶不会产生对“booktabs”包的引用,这可能是正确使用 kable 的“booktabs = TRUE”参数所必需的(它直接来自 booktabs 文档,因此应该可以工作)。

请让我知道如何实现我正在尝试的目标...

约翰

4

3 回答 3

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. 字幕格式是降价的。
  2. 正确理解“^2^”等。
  3. 引用效果很好。
于 2016-06-11T14:28:23.333 回答
0

由于您正在编织 PDF,因此输出kable()将自动检测到这一点,并被格式化以生成乳胶。

因此,您需要使用乳胶指令来格式化您的文本。

尝试这个:

  1. 将块选项设置为results = 'asis'
  2. 用于\\textbf{}产生粗体

例如:

```{r test-table, tidy=FALSE, echo = FALSE, results='asis'}
library(knitr)
kable(
  data.frame(
    Citation = c("@WatsonCrick1953"),
    Formatted.String = c("Some--Thing^2^")),
  caption = "\\textbf{Bold} in a caption -- ;"

)
```

在此处输入图像描述

于 2016-06-10T16:24:04.087 回答
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"
)
```
于 2018-06-07T16:37:13.813 回答