Search code examples
rrstudior-markdownknitrrnotebook

Trailing period after section number in Rmd notebook


I have an R notebook like the following:

---
title: "R Notebook"
output: 
  html_notebook:
    number_sections: true
    toc: true
---
# First section   
## Subsection
Some text

# Second section

When rendered to Preview Notebook in RStudio, it generates numbered section titles like 1 First section, 1.1 Subsection etc. What if I want it to add a dot at the end of the number, i.e. produce 1. First section, 1.1. Subsection etc.?


Solution

  • You can use CSS for styling these numbers.

    For instance, these notebook has dot after header numbers as you want:

    ---
    title: "R Notebook"
    output: 
      html_notebook:
        number_sections: true
        toc: true
    ---
    
    ```{css, echo=FALSE}
    .header-section-number::after {
      content: ".";
    }
    ```
    
    # First section   
    ## Subsection
    Some text
    
    # Second section