Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 408
cfell Avatar asked Apr 25 '26 14:04

cfell


1 Answers

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")
```
like image 73
Yihui Xie Avatar answered Apr 27 '26 06:04

Yihui Xie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!