Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rmarkdown font size and header

I recently opened a standard Rmd file without editing anything. The default file looks like this:

Untitled.rmd

--- title: "myfile" author: "Me" date: "May 25, 2015" output: html_document fontsize: 12pt ---  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>.  When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:  ```{r} summary(cars) ```  You can also embed plots, for example:  ```{r, echo=FALSE} plot(cars) ```  Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. 

I wanted to create an html file corresponding to the above file so in a separate R script I did the following:

knit('Untitled.Rmd', 'doc.md') markdownToHTML('doc.md', 'testing.html',header = TRUE) 

For some reason the font size doesn't work and the header information that I was hoping for doesn't appear in my testing.html. Anyone know why this is happening?

like image 503
theamateurdataanalyst Avatar asked May 25 '15 22:05

theamateurdataanalyst


People also ask

How do I increase font size in R Markdown?

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,...).

How do you make the header smaller in R?

We can insert headings and subheadings in R Markdown using the pound sign # . There are six heading/subheading sizes in R Markdown. The number of pound signs before your line of text determines the heading size, 1 being the largest heading and 6 being the smallest.

What is the R Markdown font?

The RMarkdown output is based on LaTeX, and the default LaTeX font is Computer Modern.

How do I bold a header in R Markdown?

Italic, bold, and headers To write text in bold font, use a double asterix or underscores before and after the text.


1 Answers

This is what I used to control font size and color in an R-markdown file. It basically overrides the CSS style sheets without having to create a new file. The example changes the sizes of the headers and titles, as well as the inline text and the R-code text, and sets some colors as well.

In my case I needed to pack more information into a document that had a specified number of pages so I made everything smaller.

--- title: "This is a title" date: 25 May 2015 output: html_document: theme: cerulean ---  <style type="text/css">  body{ /* Normal  */       font-size: 12px;   } td {  /* Table  */   font-size: 8px; } h1.title {   font-size: 38px;   color: DarkRed; } h1 { /* Header 1 */   font-size: 28px;   color: DarkBlue; } h2 { /* Header 2 */     font-size: 22px;   color: DarkBlue; } h3 { /* Header 3 */   font-size: 18px;   font-family: "Times New Roman", Times, serif;   color: DarkBlue; } code.r{ /* Code block */     font-size: 12px; } pre { /* Code block - determines code spacing between lines */     font-size: 14px; } </style>   # H1 Header  Some body text  ## H2 Header  More body text  ### H3 Header  blah blah blah  ```{r echo=T} n <- 100 df <- data.frame(x=rnorm(n),y=rnorm(n)) ```  ### Another H3 

Update:

Added more more styles, comments, and a bit of color to make this answer more useful. And a screen shot:

enter image description here

like image 165
Mike Wise Avatar answered Oct 08 '22 18:10

Mike Wise