Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I center my YAML heading in an R markdown html document?

I want to have my YAML header information centered on my html document.

I want everything else left alligned as normal.

Can I apply any html or other code to the YAML header to make this happen?

How do I do this??

Example:

I have:

---
title: "Shiny HTML Doc"
author: "theforestecologist"
date: "Apr 14, 2017"
output:  html_document
runtime: shiny
---
like image 758
theforestecologist Avatar asked Dec 03 '22 13:12

theforestecologist


1 Answers

Here is some css styling that you can use to accomplish what you need.

  • The markdown document title uses the h1.title CSS selector
  • The markdown document author field uses the h4.author CSS selector
  • The markdown document datea field uses the h4.date CSS selector

Here is the code:

---
title: "Shiny HTML Doc"
author: "theforestecologist"
date: "Apr 14, 2017"
output:  html_document
runtime: shiny
---

<style type="text/css">

h1.title {
  font-size: 38px;
  color: DarkRed;
  text-align: center;
}
h4.author { /* Header 4 - and the author and data headers use this too  */
    font-size: 18px;
  font-family: "Times New Roman", Times, serif;
  color: DarkRed;
  text-align: center;
}
h4.date { /* Header 4 - and the author and data headers use this too  */
  font-size: 18px;
  font-family: "Times New Roman", Times, serif;
  color: DarkBlue;
  text-align: center;
}
</style>


# H1 Header

Some body text

## H2 Header

More body text



```{r echo=T}
n <- 100
df <- data.frame(x=rnorm(n),y=rnorm(n))
```

And this is what it looks like in then end:

enter image description here

like image 141
Mike Wise Avatar answered Mar 23 '23 00:03

Mike Wise