我想两者兼而有之:在报告开始时,一个浮动的TOC和一个TOC (以Rmarkdown表示)。我认为只有one才有可能.

在这里,我手动添加了一个TOC。
---
title: "Report"
author: "Anon"
date: '2022-07-20'
output:
html_document:
toc: true
toc_float: true
toc_depth: 2
collapsed: true
smooth_scroll: true
---
## Table of Contents
- R Markdown
- Including Plots
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
## Including Plots
You can also embed plots, for example:
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.我跟随这个问题,但我可以有浮动的TOC或一个TOC在开始。我两样都要。这是客户的要求之一。
发布于 2022-08-07 15:05:24
html_document使用的模板不能做到这一点,但是可以很容易地对其进行编辑,以便两者兼顾。
system.file("rmd/h/default.html",package = "rmarkdown")
$if(toc_float)$
$else$
$if(toc)$
<div id="$idprefix$TOC">
$if(toc-title)$
<h2 id="$idprefix$toc-title">$toc-title$</h2>
$endif$
$toc$
</div>
$endif$
$endif$把它们改成
$if(toc)$
<div id="$idprefix$TOC">
$if(toc-title)$
<h2 id="$idprefix$toc-title">$toc-title$</h2>
$endif$
$toc$
</div>
$endif$(即使块成为无条件的,而不是以没有设置toc_float为条件)。保存此文件,例如保存到"toc2.html“。
output:
html_document:
toc: true
toc_float: true
toc_depth: 2
collapsed: true
smooth_scroll: true
template: toc2.html这样就行了!
https://stackoverflow.com/questions/73268290
复制相似问题