可折叠桌子周围的多个bookdown/rmarkdown/knitr问题
在RStudio中,我试图将rmarkdown与(主要用于引用表格和图形的功能)结合使用,但在表格和标题中的格式设置方面遇到了麻烦。请考虑以下例子:可折叠桌子周围的多个bookdown/rmarkdown/knitr问题,r,rstudio,knitr,r-markdown,bookdown,R,Rstudio,Knitr,R Markdown,Bookdown,在RStudio中,我试图将rmarkdown与(主要用于引用表格和图形的功能)结合使用,但在表格和标题中的格式设置方面遇到了麻烦。请考虑以下例子: --- title: "Test" knit: "bookdown::render_book" output: bookdown::pdf_book: keep_tex: yes link-citations: true references: - type: article-journal
---
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
)
```
结果产品的详细信息如下:
这有多个问题:
Joh由于您正在编织PDF,因此
kable()
的输出将自动检测到这一点,并进行格式化以生成乳胶
因此,您需要使用latex指令来格式化文本
试试这个:
results='asis'
\\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 -- ;"
)
```
切换到
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"
)
```
结果如下:
我很高兴找到这篇文章,尽管我无法复制安德里的答案。我想补充一点,通过修改标题,也可以使用
pander
引用表格: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"
)
```
谢谢你的评论。“\\textbf{}”位确实可以工作,尽管这是以可移植性(无html)为代价的,这很烦人。但是,表的内部格式(上标和引用)在bookdown上下文中不起作用……正如建议的那样,`header includes:-\usepackage{booktabs}`解决了booktabs问题。您对以下问题是否也有一些建议:?非常感谢!