Code chunk background LaTeX

I am having trouble getting the background color of code chunks to change when I knit to PDF. My understanding of the code chunk options is that setting the background option should allow me to specify the background shading for code. However, it does not seem to work. MWE below. In the example I'm trying to set the background globally and locally. Neither seems to make a difference.

    keep_tex: true

knitr::opts_chunk$set(background = c(.1, 0, 0))

```{r cars-1}

```{r cars-2, background=c(0,.1,0)}

(Note that missing backticks in code chunks is deliberate and necessary to post on the site. My actual code has properly delimited chunks.)

The .tex file does not seem to do anything with the background options. From the .tex file, I see:

[LaTeX stuff]


[more LaTeX stuff]


I'm using tinytex (which is fantastic!) on Ubuntu 18.04.

1 Like

The problem goes away if I use .Rnw rather than .Rmd. I'm looking through the code, but any notion about why the two file formats are treated differently with respect to this option?

OK, I see now that this is in the docs: Background and size only work in .Rnw.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.