Use internal links in RMarkdown HTML output

前端 未结 2 364
轻奢々
轻奢々 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:04

    Here is a solution for HTML documents using jQuery:

    ---
    title: "Internal Links"
    output: html_document
    ---
    
    # First Section
    
    ## Second Section
    
    ### Third Section
    
    
    
    
    
    Go to first section
    Go to second section
    Go to third section

    As the comments point out, we simply select all headers, read out their content (e.g. "First Section") and add the attribute id with the value corresponding to the specific content to each header. Now you can link to any header using #HEADER (e.g. #First Section).


    This is of course extendable to all other elements you wish to put an anchor on. So if you want to link to any of your chunks, simply add this script to your document:

    
    

    Now you can link to the chunks by using My Chunk where i goes from 0, the first chunk, to N, the very last chunk in your document.

提交回复
热议问题