How can I add padding to code chunks in a pdf generated by Markdown?

I am rendering an RMarkdown document to PDF. I would like to add about a space of padding at the top and bottom of each code chunk (essentially, extend the grey outline/fill a little above and below the text). How can I achieve this?

My current YAML:

    latex_engine: xelatex
    highlight: kate
mainfont: Times New Roman
header-includes: \usepackage{xcolor}

Try adding


in chunk before and after

Thanks! Sorry I don't understand. You mean like this?:

df <- read.csv(here("data", "example-data.csv"))

This adds unwanted code to my chunk and just prints "\n" in the document.

Mistook the question for putting more whitespace around the output. To widen the space for the chunk itself, use <br>

I appreciate your help but I'm not sure I follow. This is rendering to pdf not html. Also
would (if html?) effectively increase the whitespace around the chunk, not the grey box.

It's ok - not a huge deal.

Bah, I grabbed the wrong version of a template—I know better, can't mix html and pdf. I can't think, then, of anything for it than to create a LaTeX macro to output one version of the chunk as formatted text and another to be both echoed and output. Probably a massive time sink.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.