R bookdown - custom title page
Asked Answered
T

2

8

How to customize title page using bookdown?

I tried using the following code in the YAML header.

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

The body.tex file was something pretty simple, just for test:

\begin{titlepage}
Hello world
\end{titlepage}
Titfer answered 24/1, 2018 at 23:14 Comment(0)
T
3

I ended up editing the _output.yml file to reference a copy of default-1.17.0.2.tex template in my R project directory using yaml template tag.

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

For some reason i had an error compiling the pdf (! Undefined control sequence...) so I included a latex command \usepackage{graphicx} in template.tex to fix it. Now it is supposed that I am free to customize title page and whatsoever.

Titfer answered 25/1, 2018 at 15:51 Comment(2)
where did you save the template.tex file? and did you create your own template?Sypher
This was helpful to me: bookdown.org/yihui/rmarkdown-cookbook/latex-template.html and github.com/jgm/pandoc/blob/master/data/templates/default.latexVagal
L
12

In the LaTeX template <R-Library>/rmarkdown/rmd/latex/default-1.17.0.2.tex we see

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

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

This means that a titlepage is created using \maketitle if a title is defined in the YAML headers. Similar for the abstract. If you remove both these tags from your YAML headers, then the content from the file body.tex will be the first to be processed and you are free to customize your titlepage there.

See the answers to this question for an alternative approach.

Latium answered 25/1, 2018 at 11:37 Comment(2)
Thanks Ralf for putting me on the track. I could not make it work properly and I was also looking for a more flexible solution.Titfer
@Titfer You are welcome. If you found my answer helpful, you might consider up-voting it.Latium
T
3

I ended up editing the _output.yml file to reference a copy of default-1.17.0.2.tex template in my R project directory using yaml template tag.

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

For some reason i had an error compiling the pdf (! Undefined control sequence...) so I included a latex command \usepackage{graphicx} in template.tex to fix it. Now it is supposed that I am free to customize title page and whatsoever.

Titfer answered 25/1, 2018 at 15:51 Comment(2)
where did you save the template.tex file? and did you create your own template?Sypher
This was helpful to me: bookdown.org/yihui/rmarkdown-cookbook/latex-template.html and github.com/jgm/pandoc/blob/master/data/templates/default.latexVagal

© 2022 - 2024 — McMap. All rights reserved.