首页 > 解决方案 > rmarkdown 包括目录

问题描述

我正在写作rmarkdown并正在导出到odt和到html. 我可以在 generatedhtml中获得一个 TOC,我可以在 generated 中获得一个 TOC odt,但是我不能同时在两者中获得一个 TOC,因为代码似乎是互斥的。

如何Rmd在两者中从同一个文件生成 TOCodthtml

这是我获取 TOC 的方法odt

---
title: Test TOC
toc: yes
toc-title: TOC
output:
  odt_document:
    keep_md: true
  html_document:
    number_sections: true
---

# Just a test document
With some text

这是我获取 TOC 的方法html

---
title: Test TOC
output:
  odt_document:
    keep_md: true
  html_document:
    toc: yes
    toc-title: TOC
    number_sections: true
---

# Just a test document
With some text

如果我将两者结合起来,我会在html.

我正在使用rmarkdown 1.12pandoc-2.7.3

标签: r-markdownpandoc

解决方案


在此处发布解决方法。但我仍然对更好的答案感兴趣。

作为一种解决方法,我在模板中重命名为tocasodt-toctoc-titleas 。odt-toc-titleodt

更详细地说,我使用这个Rmd文件:

---
title: Test TOC
odt-toc: yes
odt-toc-title: TOC
output:
  odt_document:
    keep_md: true
  html_document:
    toc: yes
    toc-title: TOC
    number_sections: true
---

# Just a test document
With some text

使用我已替换的默认 odt 模板的修改版本

$if(toc)$

经过

$if(odt-toc)$

<text:index-title-template text:style-name="Contents_20_Heading">$toc-title$</text:index-title-template>

经过

<text:index-title-template text:style-name="Contents_20_Heading">$odt-toc-title$</text:index-title-template>

推荐阅读