Use internal links in RMarkdown HTML output

前端 未结 2 374
轻奢々
轻奢々 2021-01-31 19:54

I am using R Studio to create a markdown document. I tried:

Jump to [Header 1](#anchor)

I would like

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 20:21

    Pandoc supports explicit and implicit section references for headers; see the pandoc manual.

    • explicit: you give a custom name to a header ## Test {#test} and later refer to it with a link syntax: see [the relevant section](#test).
    • implicit: headers where you don't set a custom name, like ## Test, can still be refered to: See the section called [Test].

    Both syntax should allow you to click on the link to go to the anchor, and should work in most output format. (only tested with html and pdf).

    ---
    output:  pdf_document
    ---
    
    ## A section
    
    blah blah
    
    ## A second section with a custom identifier {#custom}
    
    blah blah
    
    ## Links
    
    You can use implicit references to refer to sections
    you have not explicitly named, like this: 
    see [A section]. 
    
    You can use links to refere to sections with explicit
    references, like this: see [the second section](#custom).
    

提交回复
热议问题