In knitr, the size option works fine in a .Rnw
file, the following code generates:
\documentclass{article}
\begin{document}
<<chunk1, size="huge">>=
summary(mtcars)
@
\end{document}
However, I can't get it to work in Rmarkdown. The following code does not change the font size, as it did in .rnw
file. The same thing happens when trying to set options with opts_chunk$set(size="huge")
.
Is this the expected behavior? How does one change the chunk code font size? (I mean using knitr options, not by adding \huge
before the code)
---
title: "Untitled"
output: pdf_document
---
```{r, size="huge"}
summary(mtcars)
```
I am using RStudio Version 0.98.987, knitr 1.6 and rmarkdown 0.2.68.
Picking up the idea to alter a knitr hook we can do the following:
This snippet modifies the default chunk hook. It simply checks if the chunk option size is not equal to its default (
normalsize
) and if so, prepends the value ofoptions$size
to the output of the code chunk (including the source!) and appends\\normalsize
in order to switch back.So if you would add
size="tiny"
to a chunk, then all the output generated by this chunk will be printed that way.All you have to do is to include this snippet at the beginning of your document.
You can define you own document format by exporting something based on the following function from your package
my_package
:This will define a knitr chunk hook
size
that will put the appropriate latex command before the chunk, and\normalsize
after the chunk.Anyway, with the following R markdown you can check if it's working:
I get the following result from `markdown::render():
See also the issue I opened on github:
https://github.com/yihui/knitr/issues/1296
Per this Gist, you have to define the font size using css:
code.r
will control the font size for R code echoed from the code chunk, whilepre
will apply to any R results output from the code.A complete working .Rmd file might look like:
The resulting html renders as: