在Rstudio中,我创建一个新项目,并使用bookdown
选择book项目。内置示例可以按预期运行,并且我可以编译4本书-gitbook,html,epub和pdf。大。
下一个明显的步骤是希望同时制作幻灯片,这与beamer package
的用法非常一致,允许同时使用beamer mode
和article mode
。因此,我试图在_ output.yml
代码中添加另一个输出:bookdown::pdf_document2
。根据文档,我知道我应该能够定义base_format
以使用rmarkdown::beamer
,The package author told me I was almost right, see this link for the discussion。
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
这正是谢义辉的亲切建议。但是,当需要构建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.
我迷路了-我花了数小时寻找解决方案,但没有成功。有人能帮我吗?对不起,我无法弄清楚这一点。谢义辉一直以来都提供了令人难以置信的支持,他的评论表明这里是解决此类问题的合适场所。非常感谢。托马斯
答案 0 :(得分:4)
该错误是由于rmarkdown::beamer_presentation()
没有参数number_sections
(您无法在投影仪中对部分编号;至少Pandoc似乎不支持)引起的。
要解决此问题,您可以使用以下技巧,该技巧基本上定义了丢弃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)
```