'Change Background color of RMarkdown PDF Code Chunk

I am trying to change the code chunk formatting options in a rmarkdown document that is generated as a pdf. I want the formatting for these code chunks to be different. I want similar to

class.source="bg-info", class.output="bg-warning"

for HTML documents.



Solution 1:[1]

Not sure if I understood your question correctly. Please always include an minimum working example (MWE) with your question for greater clarity. Since it is not outline exactly what is required, a general outline is provided.

To change the code chunk formatting options in a Rmarkdown document (PDF or HTML) you can use the built-in Pandoc Syntax Highlighting styles. You can change both the background of code chunks, and the font color. All you have to do is to add the highlight in YAML.

highlight specifies the syntax highlighting style. Some alternatives are default, tango, pygments, kate, monochrome, espresso, zenburn, haddock, breezedark, and textmate. You can also use null to prevent any highlighting. For example:

title: "A nice document"
output:
  html_document:
    highlight: haddock

You can change the the appearance of your code and output with some predefined CSS classes for backgrounds in HTML: "bg-primary", "bg-success", "bg-info", "bg-warning", and "bg-danger". Arbitrary class names and user-define custom CSS rules are also allowed. A detailed discussion can be found in Yihui Xie's R Markdown Cookbook.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 a1a5az