【问题标题】:Using Rmarkdown (pagedown) and changing Table of Contents使用 Rmarkdown (pagedown) 和更改目录
【发布时间】:2019-10-12 01:11:55
【问题描述】:

大家好,我正在尝试解决这个问题,但我无路可走:

这是我的代码:

---
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”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>

我的 TOC 中的“练习 1”一词消失了。

非常感谢您的帮助

劳拉

【问题讨论】:

标签: r r-markdown pagedown


【解决方案1】:

目录由 Pandoc 自动构建:其条目与章节标题严格对应。这就是为什么在最后一个示例(带有# {-} 的示例)中,“练习 1”一词在 TOC 中消失了。

有很多方法可以实现您的目标。鉴于您的示例,最直接的方法可能是使用 CSS。

记住这个降价行

# Exercise 1{-}

导致这个 HTML sn-p

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

您可以使用以下 CSS 声明隐藏 h1 内容:

h1 {
  display: none;
}

对于这么小的 CSS,您可以在 Rmd 文件中使用 knitr CSS 引擎:

---
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>

【讨论】:

  • 太棒了!您的回答对 e 帮助很大。
猜你喜欢
  • 2019-03-29
  • 2022-11-30
  • 1970-01-01
  • 2015-05-18
  • 2020-12-31
  • 1970-01-01
  • 2016-12-25
  • 1970-01-01
  • 2018-12-04
相关资源
最近更新 更多