首页 > 解决方案 > 如何使用 bookdown 将执行摘要放在 TOC 之前?

问题描述

我有一个bookdown带有 customtemplate.tex和 custom的项目my-format.cls。我可以在我的中执行以下操作template.tex

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

\tableofcontents

\begin{body}
...

并获取摘要以采用我的自定义格式。这部分是因为摘要的内容只是一段文本,可以放在 YAML 前端。

但是,是否可以在目录之前包含执行摘要?

我知道我可以使用(在我的index.Rmd


# Executive Summary {-}

a summary here

# Introduction

this is the first numbered section

但在这种情况下,即使“执行摘要”部分标题没有编号,它也会出现在 TOC 之后。是否可以使用类似的东西来修改template.tex这样的:

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

$if(executive_summary)$
\begin{executivesummary}
% insert summary content here
\end{executivesummary}
$endif$

\tableofcontents

\begin{body}
...

我可以从未编号的执行摘要部分(即使它必须来自不同的.Rmd文件)中剥离内容(包括数字/表格/等),并将其分配给可以代替% If I insert summary content here上述引用的某个(pandoc)变量?我还需要从默认分配的(pandoc)变量中删除相同的内容。$body$

标签: r-markdownpandocbookdown

解决方案


谢谢@tarleb!我怀疑我可以通过 Lua 过滤器得到我想要的东西,但我想我找到了一种更简单的方法,就像你的答案https://stackoverflow.com/a/53885034/1785752

index.Rmd我添加的 YAML中

executivesummary: |
  
    ```{r, echo=FALSE, results='asis'}
    res <- knitr::knit_child(quiet = TRUE, 'executive-summary.Rmd')
    cat(res, sep = '\n')
    ```

但这需要一些东西:

  • “阴影”环境在序言中定义template.tex
$if(highlighting-macros)$
$highlighting-macros$
$endif$
  • executive-summary.Rmd定义,没有 YAML 和 1 级标题(“执行摘要”标题来自模板/类文件)

有趣的是,我可以只将内容放在executivesummaryYAML 部分(即跳过子文档渲染),但在这种情况下,包含字符串的代码块选项有时会被解析为 YAML 键,这会导致渲染失败。此外,2 个空格缩进的代码块在语法检查或自动完成方面没有 IDE 帮助。


推荐阅读