Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In RMarkdown, can a floating TOC be placed on the right side of page

Tags:

html

r

r-markdown

When I add a floating Table of Contents to my R-Markdown document, it always is on the left side of the page (with the content to the right), like so:

---
title: "some title"
author: "me"
date: "3/2/2020"
output: 
  html_document:
    toc: TRUE
    toc_float: TRUE
---

Default placing of floating TOC


However, I'd like to move the floating TOC to the right side of the page. How can I accomplish this? The image below is what I'd like:


enter image description here

like image 565
Jim Kloet Avatar asked Nov 02 '25 07:11

Jim Kloet


1 Answers

Insert the CSS chunk below (after YAML) and try increasing/decreasing the values of px (right and margin-left) for fine-tuning:

---
title: "some title"
author: "me"
date: "3/2/2020"
output: 
  html_document:
    toc: TRUE
    toc_float: TRUE
---

```{css toc-content, echo = FALSE}
#TOC {
  right: 270px;
  margin: 20px 0px 25px 0px;
}

.main-container {
    margin-left: 200px;
}
```
like image 187
Radovan Miletić Avatar answered Nov 03 '25 20:11

Radovan Miletić



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!