I am using R Markdown in RStudio and the knit HTML option to create HTML output. However, the font used in the ouput for plain text blocks is rather small and I would like to change it to a differnt font and increase the font size. Can someone show an example how to set the output font - workable without a lot of knowledge in html?
So far I tried at the top of my markdown document, but this doesn't work.
---
fontsize: 24pt
---
This question is related to
r
knitr
r-markdown
These answers are overly complicated. You can change the main body font size (as well as any other CSS you might want to change) simply by embedding CSS directly into the Rmarkdown document using the html <style>
tag. You do not need an entire CSS file for something so simple. If you are doing a lot of CSS then use a separate CSS file. If you are just modifying a couple of simple things I would do it like this.
---
title: "Untitled"
author: "James"
date: "9/29/2020"
output: html_document
---
<style type="text/css">
body{
font-size: 12pt;
}
</style>
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
I had the same issue and solved by making sure that 1. when you make the style.css file, make sure you didn't just rename a text file as "style.css", make sure it's really the .css format (e.g, use visual studio code); 2. put that style.css file in the same folder with your .rmd file. Hopefully this works for you.
I would definitely use html markers to achieve this. Just surround your text with <p></p>
or <font></font>
and add the desired attributes. See the following example:
<p style="font-family: times, serif; font-size:11pt; font-style:italic">
Why did we use these specific parameters during the calculation of the fingerprints?
</p>
This will produce the following output
compared to
This would work with Jupyter Notebook as well as Typora, but I'm not sure if it is universal.
Lastly, be aware that the html marker overrides the font styling used by Markdown.
You can change the font size in R Markdown with HTML code tags <font size="1"> your text </font>
. This code is added to the R Markdown document and will alter the output of the HTML output.
For example:
<font size="1"> This is my text number1</font> _x000D_
_x000D_
<font size="2"> This is my text number 2 </font>_x000D_
_x000D_
<font size="3"> This is my text number 3</font> _x000D_
_x000D_
<font size="4"> This is my text number 4</font> _x000D_
_x000D_
<font size="5"> This is my text number 5</font> _x000D_
_x000D_
<font size="6"> This is my text number 6</font>
_x000D_
To change the font size, you don't need to know a lot of html for this. Open the html output with notepad ++. Control F search for "font-size". You should see a section with font sizes for the headers (h1, h2, h3,...).
Add the following somewhere in this section.
body {
font-size: 16px;
}
The font size above is 16 pt font. You can change the number to whatever you want.
Source: Stackoverflow.com