Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

R Markdown fig.cap repeats citation

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.

question from:https://stackoverflow.com/questions/65947036/r-markdown-fig-cap-repeats-citation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...