【问题标题】:rmarkdown include TOCrmarkdown 包括目录
【发布时间】:2019-08-19 07:46:20
【问题描述】:

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

如何在odthtml 中使用相同的Rmd 文件生成TOC?

这是我在odt 中获取 TOC 的方法:

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

这是我在html 中获取 TOC 的方法:

---
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 中得到“是”作为 TOC。

我正在使用rmarkdown 1.12pandoc-2.7.3

【问题讨论】:

    标签: r-markdown pandoc


    【解决方案1】:

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

    作为一种变通方法,我在odt 模板中将toc 重命名为odt-toc,并将toc-title 重命名为odt-toc-title

    更详细地说,我使用了这个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
    

    用我替换的default odt-template 的修改版本

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多