简体   繁体   English

文本 Rmarkdown 中的块 - Xaringan

[英]Chunks in text Rmarkdown - Xaringan

I am making a xaringan presentation and I am trying to show my chunk options in R Markdown, and I need that it appears in a gray square.我正在做一个 xaringan 演示,我试图在 R Markdown 中显示我的块选项,我需要它出现在灰色方块中。

Like this image:像这张图片:

带有漂亮灰色方块的代码块

But I just get my code without that nice gray square:但我只是得到我的代码没有那个漂亮的灰色方块:

我的代码块没有漂亮的灰色方块

And of course I don't know how to put the highlights in this kind of code chunks.当然,我不知道如何将亮点放在这种代码块中。 If somebody knows how to do it, I will really appreciate it.如果有人知道该怎么做,我将不胜感激。

This is the code I wrote in order to get the chunk without the square:这是我为了获得没有正方形的块而编写的代码:

```{r echo=FALSE, comment = NA} 
cat("````
```{r, echo = TRUE, eval=TRUE, out.width = '50%', fig.align = 'center'}`r ''`

url <- 'https://media.springernature.com/full/springer-static/\nimage/art:10.1186%2Fs13059-020-02088-y/MediaObjects/13059_2020_2088_Fig1_HTML.png'

knitr::include_graphics(url) 

```\n````")

```

Following the example in the "Ninja" presentation template, you can produce "raw chunks" by using the markdown formatting with some tricks:按照“忍者”演示模板中的示例,您可以使用markdown格式和一些技巧来生成“原始块”:

# Test

````markdown
`r ''````{r, echo = TRUE, eval=TRUE, out.width = '50%', fig.align = 'center'}

url <- 'https://media.springernature.com/full/springer-static/\nimage/art:10.1186%2Fs13059-020-02088-y/MediaObjects/13059_2020_2088_Fig1_HTML.png'

knitr::include_graphics(url) #<<
```
````

Output:
```{r, echo = TRUE, eval=TRUE, out.width = '50%', fig.align = 'center'}

url <- 'https://media.springernature.com/full/springer-static/\nimage/art:10.1186%2Fs13059-020-02088-y/MediaObjects/13059_2020_2088_Fig1_HTML.png'

knitr::include_graphics(url) #<<
```

Line highlighting is done with #<< .行高亮是用#<<完成的。 For this, you need to enable the highlighting in the yaml header (again, I've taken the default from the Ninja template):为此,您需要在 yaml header 中启用突出显示(同样,我从 Ninja 模板中采用了默认设置):

output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM