简体   繁体   English

使用针织HTML的RMarkdown:如何在TOC中隐藏子弹(目录)?

[英]RMarkdown with knitr to HTML: How to hide bullets in TOC (table of contents)?

How can I suppress the bullet points in front of the TOC items in the created HTML file? 如何在创建的HTML文件中抑制TOC项目前面的项目符号 I want to see only the headline numbers... 我只想看标题数字......

Example Test.Rmd file: 示例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

The TOC of the resulting HTML document will look like this (with the unwanted bullet points - here indicated via the * char): 生成的HTML文档TOC将如下所示(带有不需要的项目符号 - 此处通过* 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
...

The reason for bullet points is the li tag that knitr uses with the default HTML template. 项目符号的原因是knitr与默认HTML模板一起使用的li标记。 The created HTML code looks like this: 创建的HTML代码如下所示:

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

I read a little bit about CSS to suppress bullet points but I have no idea to solve this issue: 我读了一些关于CSS来压制要点,但我不知道要解决这个问题:

how to hide <li> bullets in navigation menu and footer links BUT show them for listing items 如何在导航菜单和页脚链接中隐藏<li>项目符号但是显示列表项目

Put this in styles.css : 把它放在styles.css

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

And then use this in the Rmd header YAML: 然后在Rmd头YAML中使用它:

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

That will give you the #'s but no •'s. 这会给你#,但没有。 NOTE: styles.css and your Rmd file need to be in the same directory. 注意: styles.css和您的Rmd文件需要位于同一目录中。

If you want to avoid having an additional (css) file besides the HTML file you can put the CSS code into your Rmd file directly: 如果你想避免在HTML文件之外有一个额外的(css)文件,你可以直接将CSS代码放入你的Rmd文件中:

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

<style type="text/css">
div#TOC li {
    list-style:none;
    background-image:none;
    background-repeat:none;
    background-position:0; 
}
</style>
Your content starts here...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM