【问题标题】:How can I put an executive summary before the TOC using bookdown?如何使用 bookdown 将执行摘要放在 TOC 之前?
【发布时间】:2021-01-14 21:49:11
【问题描述】:

我有一个带有自定义template.tex 和自定义my-format.clsbookdown 项目。我可以在我的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 文件)中剥离内容(包括数字/表格/等)并将其分配给一些(pandoc)变量,参考代替上面的% If I insert summary content here?我还需要从默认分配的(pandoc)$body$ 变量中删除相同的内容。

【问题讨论】:

标签: r-markdown pandoc bookdown


【解决方案1】:

感谢@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 级标题(“执行摘要”标题来自模板/类文件)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多