9

I am using knitr to create a HTML webpage. The default setting seems to be 800px but I need a larger page size of 1100px

body {
    max-width: 800px;
    margin: auto;
    padding: 1em;
    line-height: 20px ; 
}   

I have tried:

library("markdown")
library("knitr")
knit2html("test.Rmd",options = c(width=1100))

But this still gives me the smaller page size of 800px

How can I set the code for the HTML page width?

Shehary
  • 9,926
  • 10
  • 42
  • 71
adam.888
  • 7,686
  • 17
  • 70
  • 105

2 Answers2

6

Add a css element to your document, e.g.

---
title: "test"

output:
  html_document:
    css: "test.css"
---

and then put your new css information in that file, e.g.

body {
  max-width: 1100px;
  margin: auto;
 padding: 1em;
 line-height: 20px ; 
}   
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
csgillespie
  • 59,189
  • 14
  • 150
  • 185
  • 1
    Thanks. For some reason this didn't work for me but then I tried: which worked fine. – adam.888 Feb 12 '15 at 17:05
  • This only works if I add the `!important` rule to the `max-width` definition as proposed in [this answer](https://stackoverflow.com/a/38373846/7196903). Using that rule [seems bad practice](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#The_!important_exception), so is there another way? – Salim B Nov 02 '17 at 16:30
  • 5
    This also didn't work for me (nothing changed). @adam.888 could you share where/how you added "" to make it work? Thanks! – Random Certainty Dec 12 '17 at 21:21
0

A bit late, but for whom are struggling with widths in 2022 below my code that I put after YAML:

<style>
    .main-content, .toc {
      max-width: 90rem;
      padding: 2rem 4rem;
      margin: 0 auto;
      font-size: 1.1rem;
    }
</style>

That finally works for me.