代码之家  ›  专栏  ›  技术社区  ›  Laura

使用Rmarkdown(pagedow)并更改内容选项卡

  •  1
  • Laura  · 技术社区  · 5 年前

    大家好,我正试图解决这个问题,但我没有办法:

    这是我的代码:

    ---
    title: "A Multi-page HTML Document"
    author: "Yihui Xie and Romain Lesur"
    date: "`r Sys.Date()`"
    output:
      pagedown::html_paged:
        toc: true
        toc_depth: 3
        # change to true for a self-contained document, but it'll be a litte slower for Pandoc to render
        self_contained: false
    ---
    
    # Exercise 1{-}
    
    <div style="width: 100%; height: 20px; border-bottom: 1px solid black; text-align: center">
      <span style="font-size: 40px; background-color: white; padding: 0 10px;">
        Exercicio 1 <!--Padding is optional-->
      </span>
    </div>
    

    我想保存目录结构。换句话说,我想点击“练习1”,它会把我带到练习1的页面。 我希望标题为下面的自定义标题(我希望单击“练习1”e仅查看下面的练习1样式):

    <div style="width: 100%; height: 20px; border-bottom: 1px solid black; text-align: center">
      <span style="font-size: 40px; background-color: white; padding: 0 10px;">
        Exercicio 1 <!--Padding is optional-->
      </span>
    </div>
    

    例如,如果我这样做:

    # {-}
    <div style="width: 100%; height: 20px; border-bottom: 1px solid black; text-align: center">
      <span style="font-size: 40px; background-color: white; padding: 0 10px;">
        Exercicio 1 <!--Padding is optional-->
      </span>
    </div>
    

    非常感谢你的帮助

    0 回复  |  直到 5 年前
        1
  •  7
  •   RLesur    5 年前

    目录由Pandoc自动构建:其条目严格对应于章节标题。这就是为什么在最后一个示例中(使用 # {-}

    有很多方法可以实现你的目标。举个例子,最简单的方法可能是使用CSS。

    记住这个降价线

    # Exercise 1{-}
    

    <div id="exercise-1" class="section level1 unnumbered">
      <h1>Exercise 1</h1>
      ...
    </div>
    

    你可以藏起来 h1

    h1 {
      display: none;
    }
    

    对于如此小的CSS,您可以使用 knitr CSS引擎在您的 Rmd

    ---
    title: "A Multi-page HTML Document"
    author: "Yihui Xie and Romain Lesur"
    date: "`r Sys.Date()`"
    output:
      pagedown::html_paged:
        toc: true
        toc_depth: 3
        # change to true for a self-contained document, but it'll be a litte slower for Pandoc to render
        self_contained: false
    ---
    
    ```{css, echo=FALSE}
    h1 {
      display: none;
    }
    ```
    
    # Exercise 1{-}
    
    <div style="width: 100%; height: 20px; border-bottom: 1px solid black; text-align: center">
      <span style="font-size: 40px; background-color: white; padding: 0 10px;">
        Exercicio 1 <!--Padding is optional-->
      </span>
    </div>
    
    推荐文章