R Markdown fig.cap repeats citation

282 views Asked by At

I am trying to create a figure legend. My figure caption is quite long, so I'm referencing it as part of the text.

Here is the section of the R Markdown:


A reference to the figure in the text (See Figure @ref(fig:fig))

    ```{r fig, fig.cap="(ref:fig)"}
    fig
    ```

(ref:fig) This legend describes the plot "fig".


When knitted, this should look like the following:

A reference to the figure in the text (See Figure 1)

an image of the figure here

Figure 1: This legend describes the plot "fig".


However, instead I get:

A reference to the figure in the text (See Figure 1)

an image of the figure here

Figure 1: (ref:fig)

(ref:fig) This legend describes the plot "fig".


I'm not sure why it's repeating "(ref:fig)" even though it recognises it as Figure 1. Any help on this would be much appreciated.

1

There are 1 answers

3
ViviG On

This might have something to do with your YAML. Numbered figure caption is an output from Bookdown. To use it you have to change the YAML to

---
title: A title
output:
   bookdown::html_document2: default
---

The YAML above will give you the results you are after.