如何更改 Quarto 中代码块的字体大小?

问题描述 投票:0回答:1

我正在使用

quarto
准备 Beamer 演示文稿。我想减小给定块内代码的字体大小,以便一切都更合适。请看下面的例子:

生成chunk的代码是:

```{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)))
```

有没有办法更改此块的字体大小,以便所有代码行都适合 pdf 中的一行?提前致谢!

pdf r-markdown quarto beamer
1个回答
0
投票

指定一个

monofont
并使用
monofontoptions
缩小字体。

---
title: "Small code font"
format: beamer
jupyter: python3
pdf-engine: lualatex
monofont: 'Source Code Pro'
monofontoptions: 
  - Scale=0.55
---

## Portfolio

Let's do this computation in python.....


```{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)))
```

© www.soinside.com 2019 - 2024. All rights reserved.