Increase width of table of contents in rmarkdown

Viewed 745

Does anyone know how to increase the width of a floating table of content in rmarkdown so that it can show all titles in one line with no break. Here is an example:

---
title: "Title"
author: "Author "
date: '`r format(Sys.Date(), "%B %d, %Y")`'
output:
  html_document:
    toc_float: true
    toc: true
    number_sections: true
    code_folding: show
theme: lumen
editor_options: 
  chunk_output_type: console
---

# A loooooooooooooooooooooooong title

Thanks

1 Answers

What did the trick for me was to change the CSS style of the floating TOC. You can use a CSS code chunk to embed the CSS rules directly in your Rmd document. For example, like this:

title: "XY"
author: "XX"
date: '`r format(Sys.Date(), "%B %d, %Y")`'
output:
  html_document:
    toc: true
    theme: united 
    toc_depth: 4
    toc_float: true
.tocify .tocify-header {
    position: fixed;
    top: 50px;
    left: 50px;
    width: 500px;
    height: 200px;
}

Or you can include this in a custom stylesheet:

output:
  html_document:
    css: "style.css"
Related