在Rstudio中,我创建一个新项目并使用bookdown选择book项目。内置示例可以按预期运行,并且我可以编译4本书-gitbook,html,epub和pdf。大。
下一步显然是要同时制作幻灯片,这与beamer package的内容非常一致,允许同时使用beamer modearticle mode。因此,我试图在_ output.yml代码中添加另一个输出:bookdown::pdf_document2。根据文档,我知道我应该能够定义base_format以使用rmarkdown::beamerThe package author told me I was almost right, see this link for the discussion
删节:我将此修订后的_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.

我迷路了-我花了数小时寻找解决方案,但没有成功。有人能帮我吗?非常抱歉,我无法弄清楚这一点。谢义辉一直以来都提供了令人难以置信的支持,他的评论表明这里是解决此类问题的合适场所。非常感谢。托马斯

最佳答案

该错误是由于rmarkdown::beamer_presentation()没有参数number_sections导致的(您无法在Beamer中编号部分;至少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)
```

08-25 05:27