dayne
dayne

Reputation: 7784

How to add quotation marks in caption (bookdown)

I am having an issue with quotation marks inside captions using bookdown. The following rmarkdown doc illustrates the issue.

---
title: "testdoc"
author: "Dayne Filer"
date: "10/21/2020"
output:
  pdf_document: default
  html_document: default
---

In the main document, "quotation marks" are appropriately typeset. 

```{r}
knitr::kable(matrix(1:2), caption = "In a caption, \"they are not\".")
```

```{r}
knitr::kable(matrix(1:2), caption = '"I did try some alternatives...".')
```

```{r}
knitr::kable(matrix(1:2), caption = '\`\`this works for latex, but not html.\'\'')
```

The above compiles correctly for both html and latex (except the last table, which compiles correctly for latex, but NOT html). However, copying the body of the document into "A Minimal Book Example" provided with bookdown does not typeset the correct quotation marks. I have tried using both xelatex and pdflatex to compile the documents. For xelatex, it gives the following:

enter image description here

pdflatex gives:

enter image description here

Upvotes: 4

Views: 1129

Answers (1)

dayne
dayne

Reputation: 7784

As pointed out by the bookdown author, Yihui Xie, when writing long captions, or captions with special characters (e.g. quotation marks), authors should use text references.

In the above example, it would look like this:

In the main document, "quotation marks" are appropriately typeset. 
And when using text references, 

(ref:tabCap) "quotation" marks are properly formatted.

```{r}
knitr::kable(matrix(1:2), caption = '(ref:tabCap)')
```

Upvotes: 3

Related Questions