Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8088281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:02:36+00:00 2026-06-05T19:02:36+00:00

How to add table of contents to R Markdown HTML file using pandoc but

  • 0

How to add table of contents to R Markdown HTML file using pandoc but retain all the HTML formatting and header information?

E.g., If I had a file called test.html, I tried:

pandoc -s -S --toc test.html -o test-toc.html

This adds the table of contents but it removes the existing header information which makes all the formatting attractive.

Thus, it makes this html file look like this one. I’d like to preserve the formatting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:02:38+00:00Added an answer on June 5, 2026 at 7:02 pm

    I’m not sure how you can tell Pandoc to keep all the style and header information. However, presumably this style does not change very much, so why don’t you copy this into a .css stylesheet file and point to this file when generating the output HTML (with the -c or --css command line options)? You can tell Pandoc to embed this stylesheet information into your final output using the --self-contained command line option (see here for the full list of options).

    For the MathJax script in your input HTML file you can use

    --mathjax=https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
    

    Finally, for the R syntax highlighter you can use

    --include-in-header=r_syntax.html
    

    where r_syntax.html contains the appropriate JavaScript wrapped in <script> tags.

    Update: Having said all that, you can include all the style and script information in a single file (say r_styling.html) and include this at the end of the header of your output HTML using

    pandoc -s -S --toc -h r_styling.html --self-contained test.html -o test-toc.html
    

    The -h option is shorthand for --include-in-header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a table of contents for my LaTex document. The
In Wikispaces, when you add a Table of Contents to the Main Content area,
How can I add a table of contents after the beginning of a chapter?
I'm trying to add images to table cells in a grouped UITableView but the
I'm trying to create a Table of Contents for a small publication using Filemaker
I'm trying to add html around div contents that my jquery function returns after
Is it possible to add a table view on the cells of a table
I am trying to add a table in aspx page and need to have
I have a composite and want to add a table to it. So far
So here's my schema (give or take): cmds.Add(@CREATE TABLE [Services] ([Id] INTEGER PRIMARY KEY,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.