0% found this document useful (0 votes)
20 views3 pages

Latex - Changing The Font of The Document Title and Author Names in Markdown - Stack Overflow

The document discusses how to change the font size and color of the title and author names in RMarkdown PDF documents using LaTeX commands. It provides a reproducible example that includes necessary LaTeX packages and commands to customize the document header. Additionally, an alternative solution using CSS is mentioned for styling the title and author directly.

Uploaded by

Alex Nevsky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Latex - Changing The Font of The Document Title and Author Names in Markdown - Stack Overflow

The document discusses how to change the font size and color of the title and author names in RMarkdown PDF documents using LaTeX commands. It provides a reproducible example that includes necessary LaTeX packages and commands to customize the document header. Additionally, an alternative solution using CSS is mentioned for styling the title and author directly.

Uploaded by

Alex Nevsky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

Asked 9 years, 9 months ago Modified 2 years, 7 months ago Viewed 4k times

7 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

latex r-markdown

Share Improve this question Follow edited May 7, 2017 at 15:38 asked May 4, 2015 at 13:25
Martin Schmelzer user3359624
23.9k 8 78 105 324 4 14

2 Answers Sorted by:


3 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:

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

Share Improve this answer Follow edited Jan 10, 2018 at 15:51 answered May 7, 2017 at 15:09
Martin Schmelzer
23.9k 8 78 105

Fantastic answer. Worth pointing out that you can simply use - \newcommand*\eiadfamily{\setmainfont{eiad}} if the font is already installed in the
system. – DaveRGP Jan 10, 2018 at 15:50
1 Just adding a CSS code chunk solved it for me:

{css echo=FALSE}
.author {color: black; font-family: cursive }
.title {color: black; font-family: cursive }

Share Improve this answer Follow edited Jun 24, 2022 at 0:16 answered May 12, 2021 at 7:54
loops Ibraheem El Ansari
5,635 2 26 67 91 1 1 7

You might also like