I've just started playing with some of the new knitr features in RStudio.
I've tried selecting several of the different themes in the R Markdown settings dialogue but these don't seem to have any noticeable impact on the style of my resulting document. Should it, or am I missing something? Everything just seems to come out in the default style no matter what theme I select.
---
output:
html_document:
number_sections: yes
theme: spacelab
toc: yes
pdf_document: default
word_document: default
---
Installation details:
I had the same problem. Learning the following led me to the solution.
Two different things show up if you google "knitr theme".
highlight
parameter = syntax highlighting ( 1 , 2 , 3 —familiar keywords like kate, tango, solarized-dark) theme
parameter = bootswatch CSS (these are the less familiar keywords like spacelab , superhero, united, yeti) Here are the instructions of how to add the correct knitr flags at the top of your .Rmd
file.
Once you've added something like
---
title: "Impressive Client Report"
output:
html_document:
theme: spacelab
highlight: neon
---
to the top, then open R
in the directory where your .Rmd
file lives, and run
require(knitr)
knit(input='impressive report.Rmd', output='impressive_report.Rhtml')
(I switched to
_
because of another gotcha: I was switching between command-line R
and RStudio knitting, not realising that RStudio was creating a different .html
file to the one R
was creating.)
Or in the case of RStudio, just Ctrl + Shift + K to knit
your .Rmd
file from the editing window— after changing both theme
and highlight
to valid values.
I had this exact same problem and I was able to solve it by placing the theme argument before any other arguments. I am unsure if the order matters, but in my case it did. For example, this correctly changes my html theme:
---
title: "A Title"
author: "An Author"
date: "last update: `r format(Sys.Date(), format = '%d %B %Y')`"
output:
html_document:
theme: flatly
highlight: haddock
toc: true
toc_float:
collapsed: false
smooth_scroll: true
---
While providing the theme argument towards the end did not work:
---
title: "A Title"
author: "An Author"
date: "last update: `r format(Sys.Date(), format = '%d %B %Y')`"
output:
html_document:
toc: true
toc_float:
collapsed: false
smooth_scroll: true
theme: flatly
highlight: haddock
---
This also was true for my syntax highlighting argument.
Be sure that you activate the following option in your RStudio: Tools --> Global Options... --> Sweave --> Weave Rnw files using: knitr
At least it worked with me while compiling pdf from tex format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.