Author with affiliation in bookdown: HTML and pdf

If you are using Yihui Xie's bookdown package, it is quite easy to add authors and affiliations for HTML output. You only need to put the following pandoc options in the header of index.Rmd.

author:
- name: John Doe
  email: me@johndoe.com
  affiliation: A really important institute

However, this will destroy the rendering of author in pdf output. In fact there is an issue in the bookdown repo exactly about this. The only solution mentioned there is to create your own pandoc template, but I found a somewhat simpler solution. Since the issue is closed, I will post my solution here.

In your YAML header you can add a header-includes: option where you can put raw input for the latex preamble. Here's what I use in my Data Validation Cookbook:

header-includes:
- |
  ```{=latex}
  \usepackage{authblk}
  \author{Mark P.J. van der Loo\\ mpj.vanderloo@cbs.nl}
  \affil{Statistics Netherlands \\
         \href{https://www.cbs.nl}{\texttt{https://www.cbs.nl}} 
        }
  ```

Here, the authblk LaTeX package takes care of typesetting the author and affiliations. I am not sure if this will work with multiple authors and multiple affiliations.

As a reference: the complete YAML header.

This entry was posted in programming, R and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

*