[This article was first published on R – Mark van der Loo, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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: [email protected]
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\\ [email protected]}
\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.