Latex in document referencing via Varioref is not working in Rmarkdown

Viewed 16

I've been using vanilla latex documents for a long time and have recently switched over to Rmarkdown. I'm struggling to get varioref to work, or any in-document referencing for that matter. See below example Rmarkdown file contents. I've tried to make it a minimally reproducible example.

---
title: "vref"
output: 
   pdf_document: 
      keep_tex: true
latex_engine: pdflatex
header-includes: \usepackage{varioref}
---

Please see \vref{section}

\newpage

\section{This is a section} \label{section}

It seems like the reference is being created with a clickable link, but there is no reference to the section being created..

1 Answers

Rmarkdown producing unnumbered sections has nothing to do with varioref. You can make them numbered like this:

---
title: "vref"
output: 
   pdf_document: 
      keep_tex: true
latex_engine: pdflatex
header-includes: 
  - \usepackage{varioref}
  - \setcounter{secnumdepth}{4}
---

Please see \vref{section}

\newpage

\section{This is a section} \label{section}
Related