【问题标题】:How to add title to R markdown TOC如何将标题添加到 R markdown TOC
【发布时间】:2015-06-17 11:23:55
【问题描述】:

是否可以在 R Markdown 文档生成的 TOC 中添加标题。

具体来说,我现在有这样的东西:

---
title: "The Rebel Base Locations"
author: "Darth Vader"
date: "A long time ago in a galaxy far far away"
output: 
  html_document:
    css: custom.css
    toc: true
    toc_depth: 3
    number_sections: true
---

我想要的是 TOC 有一个名为“内容”的标题。我能够使用一些 css 将它推到左边。

【问题讨论】:

    标签: r r-markdown


    【解决方案1】:

    您可以在 html 模板中的目录之前添加一个新字段。关注this instructions,执行以下操作:

    1. 将 html 模板复制到您的 .rmd 文件中,并将 $toc$ 字段更改为如下内容:
    $if(toc)$
    <div id="$idprefix$TOC">
    <h1 class="toctitle">$toctitle$</h1>
    $toc$
    </div>
    $endif$
    
    1. 然后,将toctitletemplate 字段添加到您的RMarkdown 文件中。例如:
    toctitle: "Contents"
    output: 
      html_document:
        template: toctitle.html
        css: custom.css
        toc: true
        toc_depth: 3
        number_sections: true
    

    这应该在您的目录之前添加标题。您可以进行其他修改,例如从 h1 更改为另一个标签和/或使用 CSS 上的字段类。如果您因为不使用默认模板而遇到问题(mathjax 不起作用),您可以更改默认样式,以后不将totctitle 添加到不同的 rmd 文件应该没有问题。

    【讨论】:

    • @Mox,这几乎可以工作,除非我收到警告:“当不使用 rmarkdown“默认”模板时,MathJax 不适用于 self_contained。” -- 问题是我需要 MathJax!
    • 如果您需要 MathJax,我认为最好的选择是编辑原始模板。这个小添加应该不是问题。
    • 当 toc_float: true 时可能?如何
    猜你喜欢
    • 1970-01-01
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    相关资源
    最近更新 更多