Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross references to figures #12

Open
MikkoVihtakari opened this issue Apr 3, 2022 · 1 comment
Open

Cross references to figures #12

MikkoVihtakari opened this issue Apr 3, 2022 · 1 comment

Comments

@MikkoVihtakari
Copy link

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")`
@svmiller
Copy link
Owner

svmiller commented Apr 3, 2022

Pretty sure you can. You can see how I do this here through {bookdown}

https://github.com/svmiller/peacesciencer/blob/master/manuscript/src/render_pdf.R

Alas, you are right that I built the article2 function to not use {bookdown}. Let me look into this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants