首页 > 解决方案 > RMarkdown:通过 CSS 折叠目录

问题描述

我有一个 Rmarkdown 文档,左侧有一个目录 (TOC)。

rmd 文件有一个 YAML 标头:

---
title: "Foo"
author: "Bar"
date: "`r format(Sys.time(), '%d-%B-%Y')`"
output: 
  html_document:
    css: bam.css
    theme: flatly
    toc: true
---

这是 bam.css 的全部内容:

#TOC {
  position: fixed;
  left: 10px;
  top: 10px;
  width: 200px;
  height: 100%;
  overflow:auto;
}

#TOC::before {
  content: "";
}

body {
  max-width: 800px;
  margin: auto;
  margin-left:230px;
  line-height: 20px;
}

有没有一种简单的方法来修改这个 CSS 以便 TOC 将手风琴?

标签: cssr-markdown

解决方案


我发现最简单的方法是通过toc_floatYAML 标头。例如,:

 output: 
  html_document:
    theme: flatly
    toc: true
    toc_float: true

推荐阅读