Author with affiliation in bookdown: HTML and pdf

[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.

To leave a comment for the author, please follow the link and comment on their blog: R – Mark van der Loo.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)