Changing Font in PDF Produced by Rmarkdown

rmarkdown PDF custom font

The line header-includes: is missing. Try with the following header:

---
title: "Untitled"
author: "Someone"
date: "7/8/2021"
output:
pdf_document:
latex_engine: lualatex
header-includes:
- \usepackage{fontspec}
---

\setmainfont{Round Style}

Change font size in RMarkdown PDF

Did you try this?:

---
title: "Example"
author: "Tales Martins"
output:
pdf_document:
toc: true
number_sections: yes
linestretch: 1.5
---

Add in the YAML linestretch: 1.5, after that
change this toc: TRUE to this toc: true and number_sections: TRUE to number_sections: yes

An example here

https://i.stack.imgur.com/VEdLL.png

also you can select linestretch: 2 and others

Changing font in R Markdown to Times New Roman

This code may work for you:

---
title: "Times"
author: "bttomio"
date: "October 18, 2017"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{fontspec}
- \setmainfont{Times New Roman}
---

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

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

Another option:

---
title: "Times"
author: "bttomio"
date: "October 18, 2017"
output:
pdf_document:
latex_engine: xelatex
mainfont: "Times New Roman"
---

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

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

-output

Sample Image

How to change font size and type in the middle of a R markdown document?

We may use LaTeX codes inside your rmarkdown script. Set the font type with \fontfamily{}, some font codes can be found here. (Note that I am using Palatino here because Garamond is probably not installed on my system.) Font size can be set with \fontsize{}{}, where the first {} stands for the size, the second for the spacing. To make this just temporary I suggest to embed it into a \begingroup and \endgroup. Leave your YAML header as it is.

This line is normal text.

\begingroup
\fontfamily{ppl}\fontsize{14}{16}\selectfont
This line uses Garamond font and font size 14.
\endgroup

\begingroup
\fontfamily{phv}\fontsize{16}{18}\selectfont
This line uses arial font and font size 16.
\endgroup

This line is normal text.

Result

Sample Image

Change font and color for figure captions in Rmarkdown in PDF output

You could try this:

---
title: "Untitled"
author: "bttomio"
date: "6/13/2021"
output: pdf_document
---

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

```{r pressure, echo=FALSE, fig.cap="\\textcolor{red}{This is red} and \\textcolor{blue}{this is blue}"}
plot(pressure)
```

-output

Sample Image

How to change font style font with Rmarkdown-PDF , already sent error : Failed to find a package that contains Times New Roman

As @RalfStubner has already mentioned, you can use TeX Gyre Termes to embed a font like Times New Roman.

Install tex-gyre

In order to use TeX Gyre Termes, you need to install tex-gyre package from CTAN. If you have installed @Yihui's TinyTeX, type the following code to R console.

tinytex::tlmgr_install("tex-gyre")

The code above is equivalent to executing the code below in your bash.

tlmgr install tex-gyre

Provide .tex file to specify font(s) you want

Setting mainfont: in the YAML header should also work. However, here I show how to set fonts by including a .tex file, say font-config.tex for instance, to the YAML section. By the font-config.tex file, you can configure more detailed options, like Scale=MatchUppercase.

In the following font-config.tex, TeX Gyre Termes, or Times New Roman is set as the main font (\rmfamily) and TeX Gyre Heros, so-called Helvetica or Arial is specified as the san serif font (\sffamily). Save the file in your current directory.

font-config.tex

\usepackage{fontspec}

%rmfamily
\setmainfont[Scale=MatchUppercase]{TeX Gyre Termes} %Times New Roman

%sffamily
\setsansfont[Scale=1]{TeX Gyre Heros} %So called Helvetica, Arial

Include font-config.tex into the YAML header

You can call the font-config.tex from the YAML header, as shown below.

---
title: "The definitive MWE"
subtitle: "Oh, yeah"
author: "CLR"
output:
bookdown::pdf_document2:
number_sections: true
latex_engine: xelatex #or lualatex
keep_tex: true
includes:
in_header:
- font-config.tex
---

*Hellow world!* in Times New Roman.

\textsf{Hellow world!} in Helvetica.


Related Topics



Leave a reply



Submit