tch*_*ier 5 yaml r beamer r-markdown bookdown
在 Rstudio 中,我创建一个新项目并使用bookdown. 内置示例按预期完美运行,我可以编译 4 本书 - gitbook、html、epub 和 pdf。伟大的。
下一个明显的步骤是希望同时拥有幻灯片,这与 的作用非常一致beamer package,允许beamer mode和article mode。因此,我尝试在_output.yml代码中添加另一个输出: bookdown::pdf_document2。根据文档,我知道我应该能够定义要base_format使用的rmarkdown::beamer, 包作者告诉我我几乎是对的,请参阅此链接进行讨论。Punchline:我将这个修改用于_output.yml默认项目:
bookdown::gitbook:
css: style.css
config:
toc:
before: |
<li><a href="./">A Minimal Book Example</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
download: ["pdf", "epub"]
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
bookdown::pdf_document2:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
Run Code Online (Sandbox Code Playgroud)
这正是谢一辉善意的建议。但是,当需要构建 pdf_book 时,我遇到编译失败:
Output created: _book/index.html
Error in base_format(toc = toc, number_sections = number_sections, fig_caption = fig_caption, :
unused argument (number_sections = number_sections)
Calls: <Anonymous> ... <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution halted
Exited with status 1.
Run Code Online (Sandbox Code Playgroud)
我迷失了 - 我花了几个小时寻找解决方案但没有成功。有人可以帮助我吗?很抱歉我没能弄清楚这个问题。谢一辉给予了极大的支持,他的评论表明这是提出此类问题的正确场所。非常感谢。托马斯
该错误是由于rmarkdown::beamer_presentation()没有参数而导致的number_sections(您无法在投影仪中对节进行编号;至少 Pandoc 似乎不支持它)。
为了解决这个问题,您可以使用以下 hack,它基本上定义了一个丢弃参数的基本格式number_sections:
---
title: "Using bookdown with Beamer"
output:
bookdown::pdf_book:
base_format: "function(..., number_sections) rmarkdown::beamer_presentation(...)"
number_sections: false
---
## Plot
See Figure \@ref(fig:foo).
```{r, foo, fig.cap='Hi there', fig.height=4}
plot(1:10)
```
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
968 次 |
| 最近记录: |