Search code examples
rlatexr-markdown

R Markdown - Reference Section Numbers in PDF


I am using R Markdown in R Studio and have a number of sections. I am attempting to reference the section number using a custom section reference label as documented here: https://ulyngs.github.io/oxforddown/cites-and-refs.html but it doesn't seem to be working.

Here is some sample code:

Some paragraph text here

## Obtain Projected {#Projections}

Another paragraph with a reference to Section Number \@ref(Projections).

I'm hoping for the second paragraph to be rendered as:

"Another paragraph with a reference to Section Number 3.1." for example.

My relevant YAML headers are:

header-includes: |
  \usepackage{indentfirst}
  \usepackage{hyperref}
  \usepackage[utf8]{inputenc}
  \def\tightlist{}
  \setlength\parindent{24pt}
output: rticles::tf_article

Does anyone have any idea how I can get this to work?


Solution

  • I figured it out shortly after posting, so sorry to post my own answer. I simply had to add bookdown to the my YAML section:

    ---
    header-includes: |
      \usepackage{indentfirst}
      \usepackage{hyperref}
      \usepackage[utf8]{inputenc}
      \def\tightlist{}
      \setlength\parindent{24pt}
    output: 
      bookdown::pdf_book:
        base_format: rticles::tf_article
    ---
    

    And then this worked:

    Some paragraph text here

    ## Obtain Projected {#Projections}

    Another paragraph with a reference to Section Number \@ref(Projections).