【问题标题】:Format code chunk output text in markdown在 Markdown 中格式化代码块输出文本
【发布时间】:2020-02-26 18:26:01
【问题描述】:

我目前在 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】:

    只需在 Rmd 块中添加空格,它们就会传递到 beamer(它们在我的设置中执行,Windows 10 上的 R 3.6.1)。颜色会在投影仪中自动配置。

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

    【讨论】:

    • “颜色在投影仪中自动配置”是什么意思。这是否意味着无法更改棕色打印线?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多