3

Can I add more than one custom css file into R Markdown file?

I found that, add the following code in the head, I can add a customer css file.

html_document: 
  css: /css/my1.css

But this method just allowed one css file. Is it possible add more than one customer css file into a Rmd file?

1 Answer 1

2

By poring through the sources I eventually figured out that the output portion of the Rmd headers can be specified as an R function. Here is a header I use as part of my diffobj package to get two CSS files in:

---
title: "diffobj - Diffs for R Objects"
author: "Brodie Gaslam"
output:
    function(...) rmarkdown::html_vignette(..., md_extensions="-markdown_in_html_blocks", css=c(file.path(system.file(package="diffobj"), "css", "diffobj.css"), "styles.css")):
        toc: true

vignette: >
  %\VignetteIndexEntry{diffobj}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}

---

You can skip the md_extensions part for your purposes. The key is what happens with the css argument. With that argument I specify the following two files:

  • file.path(system.file(package="diffobj"), "css", "diffobj.css"), from my package
  • "styles.css", in the same folder as the vignette Rmd

The above is in the context of using devtools::build_vignettes(), but I imagine you can use a similar solution in your situation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.