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}
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.
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 Minimal Book Example</li>
after: |
<li>Published with bookdown</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.
Related
I am using bookdown package in R to compile a bookdown::pdf_book. But I am unable to knit it when I use authblk latex package. The strange thing is that I can compile the same thing outside of RStudio, even when I am using authblk latex package. Let me share a minimal example here.
Preamble taken from TeXStudio
\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{authblk}
\begin{document}
\author[1]{First Author Name}
\author[2]{Second Author Name}
\affil[1]{College1}
\affil[2]{College2}
\title{Simple Book Example}
\date{January 2013}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\include{./TeX_files/chapter01}
\include{./TeX_files/chapter02}
\backmatter
% bibliography, glossary and index would go here.
\end{document}
YAML Header from Index.Rmd page
title: "A Minimal Book Example"
author: "Author Name"
affil: "College 1"
date: "`r Sys.Date()`"
output: pdf_document
documentclass: book
bibliography:
- book.bib
- packages.bib
description: |
This is a minimal example of using the bookdown package to write a book.
set in the _output.yml file.
The HTML output format for this example is bookdown::bs4_book,
site: bookdown::bookdown_site
---
YAML header from _output.yml file
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: pdflatex
citation_package: biblatex
keep_tex: yes
Latex code in preamble.tex
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{authblk}
The problem is that when I knit (or Build pdf_book) from RStudio, the college name is not seen in the title page of the PDF book. I have tried various ways, but I am getting one or the other errors. I want to show two authors (along with their respective affiliation) on the title page of the book. But here, I can't display it even for one author when I compile it through TinyTeX in RStudio. However, when I compile the TexStudio code in TeXStudio using TinyTeX, it displays two authors and their affiliations correctly. How can I solve this?
To use a pandoc template with a normal Rmd file I add
output:
pdf_document:
template: templateName.latex
to the yaml header. But I can't figure out how to do it with bookdown. Neither
output:
bookdown::pdf_book:
pandoc_args: --template templateName.latex
nor
output:
bookdown::pdf_book:
template: tenplateName.latex
seem to work in either index.Rmd or in _bookdown.yml.
Either
output:
bookdown::pdf_book:
pandoc_args: ["--template", "templateName.latex"]
or
output:
bookdown::pdf_book:
template: templateName.latex
should work. For the first case, make sure to use an array in pandoc_args. For the second case, you had a typo (the filename should be templateName instead of tenplateName). If they don't work, please provide a reproducible example.
I am writing a thesis template according to very specific University rules, and RMarkdown won't let me include a page with the bibliography pdflatex + bibtex + pdflatex with a regular .tex file
So far I have this:
output:
pdf_document:
latex_engine: pdflatex
template: formato-uchile.tex
keep_tex: no
citation_package: biblatex
bibliography: bibliografia.bib
---
Here is the full document https://github.com/pachamaltese/template-tesis-uchile/blob/master/tesis-rmarkdown.Rmd
How can I include that bibliography page?
You do not have to indent bibliography line in the YAML section.
---
output:
pdf_document:
latex_engine: pdflatex
template: formato-uchile.tex
keep_tex: no
citation_package: biblatex
bibliography: bibliografia.bib
biblio-style: path/to/your/style-file-without-file-extention
---
As mentioned here, your bibliography will be shown in the end of the section. This is automatic, so you may need TeXing to change the order of the bibliography and appendices. If you want to do so, I highly recommend you to set keep_tex: yes so that you can get .tex file to edit.
I am rendering a book in .pdf with bookdown and I want to include several chapters.
_bookdown.yml looks like this:
book_filename: "my-Thesis"
before_chapter_script: "Script1.R" #Script1.R cleans memory (see Script1.R file)
rmd_files: ["index.Rmd", "01-intro.Rmd","02-C-quantity.Rmd","03-C-quality.Rmd","04-fine-roots.Rmd","05-aboveg-biom.Rmd","07-appendix.Rmd","08-definitions.Rmd","09-references.Rmd"]
delete_merged_file: true
_output.yml looks like this:
bookdown::gitbook:
lib_dir: assets
split_by: "rmd"
#config:
#toolbar:
#position: static
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
#citation_package: #harvard #biblatex
I would like to add an Appendix 07-Appendix.Rmd at the end of the book which covers the whole book and shows up as a chapter, not as a subchapter of the "Above-ground..." chapter as shown in the following snapshot. This is also true for the Definitions and Referenceschapters.
Any help is welcome many thanks.
Start a new markdown page with the first line:
Appendix{-}
The {-} removes numbering. I find the rmd_files listing unnecessary. Attaching an image of a page and the resulting contents listing.
I would like to use a .csl-file for formatting references with bookdown. Adding csl: some-style.csl to index.Rmd affects the output to gitbook, but not to pdf_book. I know that I can specify biblio-style, but this only accepts some standard styles and not csl-files. Is there a proper workaround?
Steps to reproduce:
Create new project with RStudio and choose "Book Project using bookdown" as option.
Download some .csl file from https://www.zotero.org/styles and copy to root of project.
Add csl: my_csl_file.csl to the header in index.Rmd.
Build the book to pdf and html, and observe the differences in the references (either in the references section, or in the introduction)
Header in index.Rmd:
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
csl: american-sociological-review.csl
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
---
HTML output (correct):
PDF output (incorrect):
I had the same problem. The following procedure worked for me:
Create new project with RStudio and choose "Book Project using
bookdown" as option.
Download some .csl file from https://www.zotero.org/styles and copy to root of project. In my case: chicago-author-date-de.csl
Set in _output.yml citation_package: none
Add in all formats (gitbook, pdf_book, epub_book) in _output.yml the line pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]
Delete or comment out in index.Rmd the line biblio-style: apalike
Replace the content of 06-references.Rmd with # References {-}
Here is my _output.yml file:
bookdown::gitbook:
css: style.css
pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]
config:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: none
pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]
keep_tex: yes
bookdown::epub_book:
pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]