r-markdown - 如何使用 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$
解决方案
谢谢@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 帮助。
推荐阅读
- java - 在 Java 中,我可以从文件中删除特定字节吗?
- php - Laravel 验证问题
- git - Git:为什么当我切换分支时我的工作目录中的文件没有改变?
- mongodb - 过滤 $geoNear (destination) 并根据 $geoNear( origin) 排序
- uinavigationbar - iPhoneX 上导航栏的渐变背景
- php - 比较数据库中的数据
- graphql - ButterCMS:RootQueryType 上的未知字段
- c++ - 为什么我不能像这样在静态成员函数中调用静态成员变量?
- grails - grails 3.3.6 中的 JSON 视图是否支持混合大小写的域类?
- python - pandas read_csv 删除空白行