RMarkdown和Knitr转换为HTML:如何在TOC(目录)中隐藏项目符号? [英] RMarkdown with knitr to HTML: How to hide bullets in TOC (table of contents)?

查看:133
本文介绍了RMarkdown和Knitr转换为HTML:如何在TOC(目录)中隐藏项目符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在创建的HTML文件中抑制TOC项前面的项目符号?我只想看到标题数字...

How can I suppress the bullet points in front of the TOC items in the created HTML file? I want to see only the headline numbers...

示例 Test.Rmd 文件:

---
title: "Untitled"
author: "Author"
date: "01/25/2015"
output:
  html_document:
    number_sections: true
    toc: yes
    toc_depth: 3
---

*Content*

# Headline 1
## Sub headline 1.1
## Sub headline 1.2
### Sub sub headline 1.2.1
# Headline 2

生成的HTML文档的目录将如下所示(带有不需要的项目符号-在此处通过* char指示):

The TOC of the resulting HTML document will look like this (with the unwanted bullet points - here indicated via the * char):

Untitled
Author

01/25/2015

* 1 Headline 1
  * 1.1 Sub headline 1.1
  * 1.2 Sub headline 1.2
    * 1.2.1 Sub sub headline 1.2.1
* 2 Headline 2
...

要点的原因是knitr在默认HTML模板中使用的li标记. 创建的HTML代码如下所示:

The reason for bullet points is the li tag that knitr uses with the default HTML template. The created HTML code looks like this:

<div id="TOC">
<ul>
<li><a href="#headline-1"><span class="toc-section-number">1</span> Headline 1</a><ul>
<li><a href="#sub-headline-1.1"><span class="toc-section-number">1.1</span> Sub headline 1.1</a></li>
<li><a href="#sub-headline-1.2"><span class="toc-section-number">1.2</span> Sub headline 1.2</a><ul>
<li><a href="#sub-sub-headline-1.2.1"><span class="toc-section-number">1.2.1</span> Sub sub headline 1.2.1</a></li>
</ul></li>
</ul></li>
<li><a href="#headline-2"><span class="toc-section-number">2</span> Headline 2</a></li>
</ul>
</div>

我阅读了一些有关 CSS 的内容,以消除要点,但我不知道要解决此问题:

I read a little bit about CSS to suppress bullet points but I have no idea to solve this issue:

推荐答案

将其放入styles.css:

div#TOC li {
    list-style:none;
    background-image:none;
    background-repeat:none;
    background-position:0;
}

然后在Rmd标头YAML中使用它:

And then use this in the Rmd header YAML:

---
title: "Untitled"
author: "Author"
date: "01/25/2015"
output:
  html_document:
    css: styles.css
    number_sections: true
    toc: yes
    toc_depth: 3
---

这将为您提供#号,但没有•号.注意:styles.css和您的Rmd文件需要在同一目录中.

That will give you the #'s but no •'s. NOTE: styles.css and your Rmd file need to be in the same directory.

这篇关于RMarkdown和Knitr转换为HTML:如何在TOC(目录)中隐藏项目符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆