R Markdown - changing font size and font type in h

2019-03-09 01:02发布

问题:

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

回答1:

I think fontsize: command in YAML only works for LaTeX / pdf. Apart, in standard latex classes (article, book, and report) only three font sizes are accepted (10pt, 11pt, and 12pt).

Regarding appearance (different font types and colors), you can specify a theme:. See Appearance and Style.

I guess, what you are looking for is your own css. Make a file called style.css, save it in the same folder as your .Rmd and include it in the YAML header:

---
output:
  html_document:
    css: style.css
---

In the css-file you define your font-type and size:

/* Whole document: */
body{
  font-family: Helvetica;
  font-size: 16pt;
}
/* Headers */
h1,h2,h3,h4,h5,h6{
  font-size: 24pt;
}


回答2:

You can change the font size in R Markdown with a 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> 

 <font size="2"> This is my text number 2 </font>
 
 <font size="3"> This is my text number 3</font> 
 
 <font size="4"> This is my text number 4</font> 
 
 <font size="5"> This is my text number 5</font> 
 
 <font size="6"> This is my text number 6</font>