Skip to content

Cross references to figures #12

Description

@MikkoVihtakari

A very basic question. How to add cross references to figures?

In bookdown::pdf_document2 we can do:

---
title: "Untitled"
author: "test"
date: "4/3/2022"
output: 
  bookdown::pdf_document2:
    toc: false
---

\```{r setup, include=FALSE} # escaping the \`, remove the \
knitr::opts_chunk$set(echo = FALSE)
\```

This is a cross reference to Figure \@ref(fig:aplot)

\``` {r, aplot, fig.cap="This is a plot"} 
plot(1)
\```

Is this possible in stevetemplates::article2?

The only way I manage is through the captioner package:

---
title: "Untitled"
author: "test"
date: "4/3/2022"
output: 
  stevetemplates::article2
---

\```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(captioner)
fig_nums <- captioner()
\```

This is a cross reference to `r fig_nums("aplot", display = "cite")`

\```{r, aplot}
plot(1)
\```
`r fig_nums(name = "aplot", caption = "This is a plot")`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions