降价格式代码块输出文本

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

我目前在RStudio中使用markdown进行投影仪演示。我有一些代码块可以生成输出,我想以某种方式格式化输出。这是一张幻灯片:

---
title: "An Introduction to Statistical Analysis with R"
author: Me
date: Now
output: 
  beamer_presentation:
     slide_level: 3
---

# Lecture 2: Creating datasets with R

### Assignments

R, like other computer languages, has *symbolic variables*, that is
names that can be used to represent values. To assign the value 2 to the
variable `x` and then work with it, you can enter

```{r, collapse=TRUE}
x <- 2
x
x+x
2*x+exp(x)
2*x*pi
```

当前,PDF文件中代码块的输出看起来像这样:

x <- 2
x
## [1] 2 
x+x
## [1] 4 
2*x+exp(x)
## [1] 11.38906 
2*x*pi
## [1] 12.56637

我想更改生成的输出的字体和颜色(即,虚线)。我也想将代码的输出空间隔开,所以看起来像这样:

x <- 2
x

## [1] 2 

x+x

## [1] 4 

2*x+exp(x)

## [1] 11.38906 

2*x*pi

## [1] 12.56637

我该如何实现?我不太喜欢knitr(尤其是语法)。从目前为止我所读到的内容中,钩子可能有用吗?我也想在全球范围内实施建议的更改。

r latex r-markdown knitr pandoc
1个回答
0
投票

只需在Rmd块中添加空格,它们就会传递给Beamer(它们在我的设置中起作用,在Windows 10上为R 3.6.1)。颜色会在投影机中自动配置。

```{r, collapse=TRUE}
x <- 2
x

x+x

2*x+exp(x)

2*x*pi
```

enter image description here

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