cfell
cfell

Reputation: 45

citing within a figure caption using r markdown

I am using R markdown with bookdown to create pdf output. As far as I can tell from this question and this github issue I am using the right syntax but it doesn't work for me I just get the "[@citation]" returned as text in the caption. Are there specific yaml, chunk options or packages I need to get this to work?

---
title: "caption citation test"
output:
  bookdown::pdf_document2
bibliography: Bibliography_mini.bib
---

```{r echo=FALSE,warning=FALSE}
 library(knitr)
 library(kableExtra)
  opts_chunk$set(fig.path='figure/graphics-', 
                 cache.path='cache/graphics-', 
                 fig.align='center',
                 external=TRUE,
                 echo=TRUE,
                 warning=FALSE,
                 fig.pos='H'
                )
  a4width<- 8.3
  a4height<- 11.7
```
Some text here look the citation works [@moravec1980obstacle]

```{r moravec, echo=FALSE, fig.cap="look the citation doesn't work 
[@moravec1980obstacle]"}
knitr::include_graphics("Moravec.png")
```

Picture of output

Upvotes: 3

Views: 2063

Answers (2)

statoconial membrane
statoconial membrane

Reputation: 37

A pure latex solution also works, which has far more control over the citation style, although is obviously limited to pdf outputs e.g. \citep{Bradshaw2010}.

Upvotes: 0

Yihui Xie
Yihui Xie

Reputation: 30114

You can use text references (see Section 2.2.4 of the bookdown book).

(ref:moravec) look the citation doesn't work [@moravec1980obstacle]

```{r moravec, echo=FALSE, fig.cap="(ref:moravec)"}
knitr::include_graphics("Moravec.png")
```

Upvotes: 7

Related Questions