首页 > 解决方案 > 为 Rmarkdwon 中的更多页面设置通用目录

问题描述

我有一些 markdown 文件,我需要 knitr 来获得由三个不同页面组成的 html 输出。每页都有一些章节(第一页1章,第二页4章,第三页4章)。我需要在每一页中重复完整的目录(包含所有章节)。使用我的代码,每个 TOC 都被拆分,并且仅指单页的章节。这是我在每个 rm 文件/页面开头的代码,我对此非常陌生,非常感谢。

---
    title: "page"
    author: "me"
    date: "26/02/2020"
    output:
      html_document:
        toc: yes
        toc_depth: 3
        toc_float:
          collapsed: yes
          smooth_scroll: yes
      word_document: default
    ---

<style type="text/css">

body{ /* Normal  */
      font-size: 14px;
  }
td {  /* Table  */
  font-size: 12px;
}
h1.title {
  font-size: 38px;
  color: DarkRed;
}
h1 { /* Header 1 */
  font-size: 28px;
  color: DarkBlue;
}
h2 { /* Header 2 */
    font-size: 22px;
  color: DarkBlue;
}
h3 { /* Header 3 */
  font-size: 18px;
  font-family: "Times New Roman", Times, serif;
  color: DarkBlue;
}
code.r{ /* Code block */
    font-size: 12px;
}
pre { /* Code block - determines code spacing between lines */
    font-size: 12px;
}
</style>

<style type="text/css">

#TOC {
  margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
  position: relative;
  width: 100%;
}
}


.toc-content {
  padding-left: 30px;
  padding-right: 40px;
}

div.main-container {
  max-width: 1200px;
}

div.tocify {
  width: 20%;
  max-width: 260px;
  max-height: 85%;
}

@media (min-width: 768px) and (max-width: 991px) {
  div.tocify {
    width: 25%;
  }
}

@media (max-width: 767px) {
  div.tocify {
    width: 100%;
    max-width: none;
  }
}

.tocify ul, .tocify li {
  line-height: 20px;
}

.tocify-subheader .tocify-item {
  font-size: 1.00em;
  padding-left: 25px;
  text-indent: 0;
}

.tocify .list-group-item {
  border-radius: 0px;
}


</style>




```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE, 
comment = "##",
tidy = TRUE

标签: htmlr-markdownknitrtableofcontents

解决方案


推荐阅读