Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the font of the document title and author names in markdown

I'm using rmarkdown to produce a pdf document with conversion done either in RStudio or by using the render() function in R. Can anyone give me some pointers for changing the size, colour etc. of the font used for the document title and author names? I have made a lot of progress with things like changing the overall font and so on by editing the front matter in the document but I am completely lost on this one. Please bear in mind that I do not speak LaTeX very well...

Thanks for any help

like image 701
user3359624 Avatar asked May 04 '15 13:05

user3359624


1 Answers

Better late than never I guess.

Changing individual parts of the default rmarkdown layout does not work without making use of a little bit of LaTeX.

First of all, here is a reproducible example:

---
title: "Lord of the Rings"
author: "J. R. R. Tolkien"
header-includes:
  - \usepackage{xcolor}
  - \usepackage{fetamont}
  - \newcommand*\eiadfamily{\fontencoding{OT1}\fontfamily{eiad}\selectfont}
  - \newcommand{\mytitle}{\eiadfamily}
  - \newcommand{\myauthor}{\ffmfamily \textcolor{blue}}
  - \pretitle{\vspace{\droptitle}\centering\huge\eiadfamily}
  - \preauthor{\centering\large\myauthor}
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


## Chapter 1

In this approach, we do not need to include a custom TeX template. We make use of the fact that rmarkdown uses the LaTeX package called titling to create the document header. The documentation can be found here.

Using the commands \pretitle and \preauthor of that package we can redefine the style of the header. The defaults that are used by rmarkdown are (see code on github)

\pretitle{\vspace{\droptitle}\centering\huge}
\preauthor{\centering\large\emph}

Now to the code. What did we do:

We imported two packages, xcolor and fetamont. The first one is needed to make use of colors and the latter one is a package containing a font we aim to use.

With the next three lines we define 3 new commands. The first one (\eiadfamily) is used to set the font family to be eiad. The other two (\myauthor, \mytitle) just combine the setting of a font and a color.

Lastly we redefine \preauthor and \pretitle to

\pretitle{\vspace{\droptitle}\centering\huge\eiadfamily}
\preauthor{\centering\large\myauthor}

(Notice that I deleted \emph from \preauthor since an oblique version of the ffm font family is not available.)

Here is the result:

enter image description here

An overview of available fonts can be found at http://www.tug.dk/FontCatalogue/.

like image 115
Martin Schmelzer Avatar answered Sep 29 '22 15:09

Martin Schmelzer