I am using quarto
to prepare a Beamer presentation. I would like to reduce the font size of the code inside a given chunk so everything fits better. See the example below:
The code that generates the chunk is:
```{python}
# Import packages
import numpy as np
```
```{python}
#| echo: true
w = np.array([0.7, 0.3])
Sigma = np.array([[0.09, 0.1], [0.1, 0.25]])
var_rp = w.T @ Sigma @ w
print("Variance of our example portfolio {:.4f}".format(var_rp))
print("Standard Deviation of our example portfolio {:.2f}".format(np.sqrt(var_rp)))
```
Is there a way to change the font size of this chunk so all lines of code fit in a single line in the pdf? Thanks in advance!
You can use \AddToHookNext{env/Highlighting/begin}{\tiny}
to change the font size of the next chunk without affecting other chunks:
---
format: beamer
---
```{python}
# Import packages
import numpy as np
```
\AddToHookNext{env/Highlighting/begin}{\tiny}
```{python}
#| echo: true
w = np.array([0.7, 0.3])
Sigma = np.array([[0.09, 0.1], [0.1, 0.25]])
var_rp = w.T @ Sigma @ w
print("Variance of our example portfolio {:.4f}".format(var_rp))
print("Standard Deviation of our example portfolio {:.2f}".format(np.sqrt(var_rp)))
```
(in case you want to change the font size of all chunks, use \AddToHook{env/Highlighting/begin}{\tiny}
in your header includes)