r-markdownknitrofficedown

Level 4 and 5 headers not included in the Table of Contents for officedown


I'm using officedown with Rmarkdown to knit word docs and currently it's not reading level 4 and 5 headers in the Table of Contents (though it's correctly adding headers levels 1-3). My YAML is:

date: XX
author: XX
title: XX
output: 
  officedown::rdocx_document:
    reference_docx: reference_style_01.docx
bibliography: Thesis.bib
csl: apa
editor_options: 
  markdown: 
    wrap: 72

and this is the code block immediately after the YAML:

knitr::opts_chunk$set(echo = FALSE, fig.cap = TRUE)
library(officedown)
library(officer)
install.packages("knitr", repo = "http://cran.rstudio.com")
library(knitr)

fp <- fp_par(
  text.align = "center", 
  padding.bottom = 20, padding.top = 120, 
  border.bottom = fp_border())

ft <- fp_text(shading.color='#EFEFEF', bold = TRUE)

I'm using #'s to identify headers. # header 1, ## header 2, and ### header 3 are correctly identified by officedown and put in the TOC. But #### header 4 and ##### header 5 aren't. Do I need to change my style guide or YAML or something else? All help appreciated.


Solution

  • Changing the table of contents block from

    <!---BLOCK_TOC--->

    to

    block_toc(level = 5)
    

    fixed it. Thanks David Gohel for the help.