Search code examples
rpdf-generationquarto

Setting code chunk size on Quarto pdf output


Any idea how to set a small size for code chunks on Quarto pdf output ? I don't want my code to have the same size of my text, but I can't find an argument in the settings in the begining of my document nor in the R code chunk to specify a font size.


Solution

  • You can define the global size of chunk text (i.e. R input and output) using the chunk options of knitr. Here an example of the content of an R-chunk as I put it into the very beginning of the Quarto (or Rmarkdown) document (with other potentially useful options; for example, I want figures to be approximately square, by default):

    #| echo: false
    library(knitr)
    opts_chunk$set(fig.align='center', fig.width=4, fig.height=4.2, 
    cache=TRUE, size="small")
    

    The argument "size" accepts the standard LaTeX sizes (as provided in the other answers). Since fixed-width fonts appear larger than variable-width fonts, "small" seems to strike a good balance between readability and space use.