How to change the position of the table of contents in rmarkdown?

前端 未结 2 1250
清酒与你
清酒与你 2020-12-08 22:58

With RStudio and knitr I see that I can add a TOC with the following code in my .rmd file.

----------------
output: 
  html_document:
    toc: yes
---------         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 23:19

    You can use JQuery to relocate the TOC to an arbitrary position in the file. Simply insert a heading where you want the TOC to go, and use the ID generated by rendering the R Markdown file. For example:

    
    

    A heading called "Table of Contents" somewhere in the R Markdown file will receive id "table-of-contents". The TOC has id "TOC". The Jquery bit above selects that TOC, and inserts it after the "Table of contents" heading, wherever in the document it's located.

提交回复
热议问题