New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show toc in a rmarkdown file? #58

likanzhan opened this Issue Feb 21, 2017 · 4 comments


None yet
4 participants

likanzhan commented Feb 21, 2017

When the document is a .md file, the table of contents from the file can be extracted via .TableOfContents. But if the file extension is .rmd, the toc cannot be extracted. Any suggestions? Thanks.


This comment has been minimized.


yihui commented Feb 22, 2017

Yes. You can add this to the YAML metadata of your Rmd document:

    toc: true

Full documentation at

@yihui yihui added this to the v0.1 milestone Feb 22, 2017

@likanzhan likanzhan closed this Apr 22, 2017


This comment has been minimized.

raybuhr commented May 4, 2017

EDIT: This is totally working, just I made some poor assumptions. For anyone who finds this in the future, don't render the .Rmd using knitr just use the blogdown::serve_site() and blogdown will do the rendering of the Rmd for you.

---- Previous

This ins't working for me.

Here is my YAML metadata:

title: "Using Hugo and Blogdown"
keywords: tech
date: '2017-05-04'
disqusIdentifier: 2c5a0040
- tech
- blog
- rmd
- blogdown
- hugo
    toc: true


I also tried substituting blogdown::html_page: with html_document, which does generate the toc in the knitted html but doesn't render correctly once hugo builds the site. Both options end up looking like this on my website:

January 1, 1
Using Hugo and Blogdown code{white-space: pre;} pre:not([class]) { background-color: white; } if (window.hljs && document.readyState && document.readyState === “complete”) { window.setTimeout(function() { hljs.initHighlighting(); }, 0); } h1 { font-size: 34px; } h1.title { font-size: 38px; } h2 { font-size: 30px; } h3 { font-size: 24px; } h4 { font-size: 18px; } h5 { font-size: 16px; } h6 { font-size: 12px; } . 

I am using hugo version 0.20.7 on ubuntu, Rmarkdown version 1.5 and blogdown version 0.0.6 fwiw.


This comment has been minimized.

hezhaobin commented May 5, 2018

Is it possible to add a checkbox in the "new post" addins to add the toc automatically? I find myself google the grammar of this all the time. Besides, will the floating TOC function be added to blogdown any time soon? Thanks Yihui for the nice work.


This comment has been minimized.


yihui commented May 7, 2018

@hezhaobin The problem for a checkbox in the New Post addin is that it is hard to tell what it should do in the case of plain Markdown posts (the implementation of TOC is theme-dependent).

For the floating TOC, it is also up to the specific Hugo theme. If you are familiar with HTML/CSS/JS, you could implement it by yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment