Style for chunks?

What is the name of the style that code chunks are output to? Right now, my code chunks come out funny with grey background and boldface purple/green highlights, but still in Times New Roman. I am using the company template in reference_docx, but of course I can add my own styles to my personal copy.

If you knit stuff without the reference file, it looks like the style for the code chunks should be Block Text, but it does not seem to be really applied to them. It is just there in the file, and it is the closest in formatting to it.

1 Like

That is strange that the code chunks don't have a clear Style associated with them. When I knit the standard R Markdown template to Word, every section is associated with a style except the code chunk and the output.

A short-term solution would be to experiment with the highlight argument. From ?word_document:

Syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", and "haddock". Pass NULL to prevent syntax highlighting.

For example, you can remove the grey background and other colors by setting this to NULL in the YAML header:

output:
  word_document:
    highlight: NULL

Unfortunately that still doesn't make the font of the code chunk match that of the Body Text style.

A potential solution, albeit convoluted, would be to use a knitr hook to add fenced_divs around the code chunk and then define custom styles in the reference docx file.

Thanks @jdblischak -- I am totally fine with colors (it's echo=FALSE a lot of the time anyway... no PI ever wants to see the code :slight_smile: ). Hooks are cumbersome, but would probably work.

Maybe I should just file an issue and have the actual developers fix :hammer_and_wrench: it.

1 Like

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