Reputation: 1686
In RStudio I'm trying to use rmarkdown in conjunction with bookdown (mostly for the capabilitites to reference tables and figures) and am running into trouble with the formatting in tables and captions. Please consider the following example:
---
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
)
```
A detail of the resulting product is:
This has multiple issues:
A further issue is that the currently produced latex does not produce a reference to the "booktabs" package, which is presumably needed to properly use the "booktabs = TRUE" argument to kable (which comes directly from the booktabs documentation and thus ought to work).
Please let me know how I may achieve what I am trying ...
Joh
Upvotes: 1
Views: 1416
Reputation: 1019
I was glad to find this post, although I just could not replicate Andrie's answer. I would like to add that it is also possible to have the table referenced using pander
by modifying the caption as such: caption = "(\\#tab:test-table) *Not bold* in a caption; **bold** in a caption;",
I modified the code to produce an article pdf document rather than a book and this code works for me:
---
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"
)
```
Upvotes: 0
Reputation: 1686
Switching to pander
does the trick:
---
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"
)
```
Upvotes: 1
Reputation: 179558
Since you are knitting to a PDF, the output of kable()
will automatically detect this, and be formatted to produce latex.
Thus you need to use latex instructions to format your text.
Try this:
results = 'asis'
\\textbf{}
to produce boldFor example:
```{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 -- ;"
)
```
Upvotes: 0