如何在rmarkdown中更改目录的位置? [英] How to change the position of the table of contents in rmarkdown?

查看:846
本文介绍了如何在rmarkdown中更改目录的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用RStudio和knitr,我可以在.rmd文件中添加带有以下代码的目录.

With RStudio and knitr I see that I can add a TOC with the following code in my .rmd file.

----------------
output: 
  html_document:
    toc: yes
-----------------

但是,这会将TOC放在HTML文档的最开始.有没有办法将目录下的目录下移?在介绍性段落之后说?

However, this places the TOC at the very beginning of the HTML document. Is there a way to move the TOC lower on the page? Say after an introductory paragraph?

我尝试使用__TOC____FORCETOC__,但是它没有改变目录的位置.

I tried to use __TOC__ and __FORCETOC__ but it did not change the TOC position.

推荐答案

TOC的位置在R Markdown默认HTML模板中是固定的.如果要更改其在文档中的位置,则需要修改模板:

The position of the TOC is fixed in the R Markdown default HTML template. If you want to change its position in the document, you'll need to modify the template:

  1. 复制R Markdown HTML模板用作起点.您可以通过运行以下R命令找到它:system.file("rmd/h/default.html", package="rmarkdown")
  2. $toc部分移动到要显示目录的位置.
  3. 将修改后的模板与要呈现的文档保存在同一文件夹中,例如lowertitle.html
  4. template: lowertitle.html添加到html_document设置.
  1. Make a copy of the R Markdown HTML template to use as a starting point. You can find it by running this R command: system.file("rmd/h/default.html", package="rmarkdown")
  2. Move the $toc section to where you want the table of contents to appear.
  3. Save the modified template in the same folder as the document you're rendering as e.g. lowertitle.html
  4. Add template: lowertitle.html to the html_document settings.

从模板的角度来看,所有文档的内容都是原子单位,因此可能有必要将要显示的所有内容放在模板本身的目录中.

From the standpoint of the template, all of the document's content is an atomic unit, so it might be necessary to put any content you want to appear before the TOC in the template itself.

这篇关于如何在rmarkdown中更改目录的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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