Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown - changing font size and font type in html output

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 --- 
like image 751
Bärbel Avatar asked Mar 26 '15 09:03

Bärbel


People also ask

How do I change font size and style in HTML?

How to Change Font Size in HTML. To change font size in HTML, use the CSS font-size property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag.

How do I change the font size in R script?

Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.

What font does RMarkdown use?

The RMarkdown output is based on LaTeX, and the default LaTeX font is Computer Modern. You will need to download and install the font on your computer. The CMU Serif version of this font is probably the one you want.

How do I format an RMD?

Firstly, open up a R Markdown file in R Studio. Click the File tab, New File , then R Markdown . Leave the default output as is (HTML), choose a title for the new R Markdown file or leave it blank. The new document generated will already contain text - this will demonstrate the basics of R Markdown.


2 Answers

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; } 
like image 72
jmjr Avatar answered Oct 14 '22 07:10

jmjr


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>      <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>
like image 30
RRuiz Avatar answered Oct 14 '22 07:10

RRuiz