Home > Net >  HTML page is left-aligned when specifying the theme to use ( R Markdown - cleanrmd package)
HTML page is left-aligned when specifying the theme to use ( R Markdown - cleanrmd package)

Time:08-21

When using the cleanrmd package for R Markdown, the output html page is left-aligned if I specify the theme to use, while it's centered when the them is set as NULL.


theme set as NULL

---
title: "TEST"
output: 
  cleanrmd::html_document_clean:
    theme: NULL
---

HTML Page when the theme is set as NULL


With a theme specified

---
title: "TEST"
output: 
  cleanrmd::html_document_clean:
    theme: new.css
---

HTML Page when a specific theme is set

Anyone can help me to fix this?

CodePudding user response:

Specify CSS rule body { margin: 0 auto; padding: 2rem;} for the entire body of the document, which will fix the issue.


---
title: "Title"
author: "Author"
date: "Date"
output: 
  cleanrmd::html_document_clean:
    theme: new.css
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{css, echo = FALSE}
body {
  margin: 0 auto;
  max-width: 750px;
  padding: 2rem;
}
```


## R Markdown

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. 

Rendered output looks like,

centered_body_of_cleanrmd_output


  • Related