R bookdown - 自定义标题页

R bookdown - custom title page

如何使用bookdown自定义扉页?

我尝试在 YAML header 中使用以下代码。

includes:
  in_header: preamble.tex
  before_body: body.tex

body.tex 文件非常简单,仅供测试:

\begin{titlepage}
Hello world
\end{titlepage}

在 LaTeX 模板中 <R-Library>/rmarkdown/rmd/latex/default-1.17.0.2.tex 我们看到

\begin{document}
$if(title)$
\maketitle
$endif$
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

$for(include-before)$
$include-before$

这意味着如果在 YAML headers 中定义了 title,则使用 \maketitle 创建标题页。 abstract 类似。如果您从 YAML headers 中删除这两个标签,那么文件 body.tex 中的内容将首先被处理,您可以在那里自定义您的标题页。

请参阅 this question 的答案以了解替代方法。

我最终编辑了 _output.yml 文件,以使用 yaml 模板标签在我的 R 项目目录中引用 default-1.17.0.2.tex 模板的副本。

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>
    edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
    download: ["pdf", "epub"]
bookdown::pdf_book:
    fig_caption: true
    number_sections: yes
    includes:
        in_header: preamble.tex
    latex_engine: xelatex
    citation_package: natbib
    keep_tex: yes
    template: template.tex
bookdown::epub_book: default

出于某种原因,我在编译 pdf 时遇到错误(!未定义的控制序列...)所以我在 template.tex 中包含了一个乳胶命令 \usepackage{graphicx} 来修复它。现在我应该可以自由定制标题页等等。