Rmarkdown: How to Change the Font Color

How to change font style, size and color in xaringan slide

To style certain lines or phrases, you need to define your own content class (say .my-style) using CSS and wrap those lines or phrases with that content class (like .my-style[lines or phrases]) and define CSS rules for styles that you want to use in CSS file styles.css. Then attach that CSS file by specifying it in the YAML key css: along with other style files.

---
title: "Econ"
subtitle: "Week 1"
author: "Instructor"
date: "`r Sys.Date()`"
output:
xaringan::moon_reader:
css: [default, metropolis, metropolis-fonts, "styles.css"]
lib_dir: libs
nature:
highlightStyle: arta
highlightLines: true
countIncrementalSlides: false

---

# Is economics a science?

--
Probably not, maybe .my-style[pseudo-science]?.

styles.css

.my-style {
font-weight: bold;
font-style: italic;
font-size: 1.5em;
color: red;
}

How to change the font color of title, author, date and make it bold in yaml of Rmarkdown?

One way is to use a latex code chunk in the title.

---
title: |
```{=latex}
\textcolor{red}{\textbf{PDF Document}}
```
author: "Sana"
output: pdf_document
---

R Markdown chunk font color changed

You can change syntax highlighting in the Yaml options of an R Markdown document:

---
title: "test"
output:
html_document:
highlight: breezedark
---

Some Test code:

```{r results='hide'}
library(tidyr)
relig_income %>%
pivot_longer(!religion, names_to = "income", values_to = "count")
```

Sample Image

---
title: "test"
output:
html_document:
highlight: pygments
---

Some Test code:

```{r results='hide'}
library(tidyr)
relig_income %>%
pivot_longer(!religion, names_to = "income", values_to = "count")
```

Sample Image

Supported styles include default, tango, pygments, kate, monochrome, espresso, zenburn, haddock, breezedark, and textmate (Source). It's not clear why the style changed for you, but I think you have to find that out yourself :)

Using hex code to change text color in RMarkdown PDF (R)

Yes, you can, see there and there:

You can also use CSS:

e.g.:

```{css echo=FALSE}
.my color {
color: #FF0000;
font-weight: 700
}
```


#R Markdown
`r sprintf("<span class='my color'>BLAH-BLAH</span>")`

To make a pdf from html. "Knit to Html" - > "Open in Browser" -> "Save as PDF..."

Rmarkdown table of contents changes font color

If you use real latex sectioning commands, you can specify both the title as it should appear in text as well as the title for the toc:

---
title: "Age Assignment"
author: "joe"
date: "`r Sys.Date()`"
output:
pdf_document:
keep_tex: true
header-includes:
- \geometry{top=1.3cm, bottom=1.0cm, left=1.8cm, right=1.8cm,footskip=.5cm}
- \usepackage{hyperref}
- \hypersetup{colorlinks = true, linkcolor = webblue, urlcolor = red}
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
- \usepackage{longtable,ctable}
- \usepackage{url}
- \usepackage{relsize}
- \usepackage[compact]{titlesec}%use 'compact' to shrink the whitespace on sections,sub,subsub
- \hypersetup{pdfstartview={XYZ null null 0.75}}%0.75 prints pdf at 75% zoom level
- \usepackage{setspace}
- \newcommand{\subsubsubsection}[1]{\paragraph{#1}\mbox{}\par\vspace{1mm}} %to add a subsubsubsection
- \setcounter{secnumdepth}{4} %to add a subsubsubsection
- \setcounter{tocdepth}{4} %to add a subsubsubsection
- \titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%Sections
- \titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%subsections
- \titlespacing\subsubsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}%subsub
- \definecolor{webblue}{rgb}{0, 0, 0.5} % less intense blue
- \definecolor{bole}{rgb}{0.47, 0.27, 0.23}
- \definecolor{brickred}{rgb}{0.8, 0.25, 0.33}
- \definecolor{niceblue}{rgb}{0.0, 0.53, 0.74}
subtitle: Assessment of populations
number_sections: yes
toc: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE,comment="")
```
\color{bole}The purpose of this document is to......\
\color{black}

# Beginning of document

## This is a test

## And this is another test...

\subsection[Introduction]{\color{niceblue}Introduction}
\color{black}
The Central Valley blah blah\par

\subsubsection[Methods]{\color{niceblue} Methods}
\color{black}
And this is what happened......

Sample Image

YAML title font and color in Rmarkdown

The other option would be to add a CSS code chunk anywhere in the dashboard

```{css}

body > div.navbar.navbar-inverse.navbar-fixed-top > div > div.navbar-header > span.navbar-brand {

font-size: 26px;
color: red;
}

```

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



Related Topics



Leave a reply



Submit