如何在 Quarto Reveal.js 演示中使代码块的输出在水平方向上可滚动?

huangapple go评论64阅读模式
英文:

How to make code chunk output scrollable horizontally in quarto revealjs presentation

问题

我之前使用R中的xaringan包创建了一个带有可滚动代码块输出的演示文稿,就像下面的照片所示。

我想在quarto revealjs演示文稿中创建相同的可滚动代码块输出。有谁知道如何在quarto演示中实现这一点?

可滚动代码块输出:
如何在 Quarto Reveal.js 演示中使代码块的输出在水平方向上可滚动?

如果有帮助的话,以下是我之前在xaringan中制作演示时使用的CSS代码。

提前感谢!

/* 可滚动代码块输出 */
.remark-code {
  display: block;
  overflow-x: auto;
  max-height: 100%;
  padding: .5em;
  color: #fff;
  background: rgb(131, 139, 139);
}
英文:

I made a presentation with a scrollable code chunk output using the xaringan package in R before like the photo shown below.

I want to make the same scrollable code chunk output in quarto revealjs presentation. Anyone knows how to do it in quarto presentation?

scrollable code chunk output:
如何在 Quarto Reveal.js 演示中使代码块的输出在水平方向上可滚动?

If it helps, here is the css code I used before when making a presentation in xaringan.

Thank you in advance!

/* scrollable code chunk output */
.remark-code {
  display: block;
  overflow-x: auto;
  max-height: 100%;
  padding: .5em;
  color: #fff;
  background: rgb(131, 139, 139);
}

答案1

得分: 3

只需要两个步骤就可以在Quarto revealjs中完成相同的操作。首先,定义一个带有overflow-x: auto的CSS类,然后将该类传递给代码块选项class-output,以便输出具有水平滚动。

第一个例子:

.hscroll {
  overflow-x: auto;
  white-space: nowrap;
}

第二个例子:

knitr:
  opts_chunk:
    class-output: hscroll

如何在 Quarto Reveal.js 演示中使代码块的输出在水平方向上可滚动?

英文:

You just need two steps to do the same in Quarto revealjs. At first, define a css class with overflow-x: auto and then pass the class to the chunk option class-output so that output of that will have horizontal scrolling.

---
title: Output Horizontal scrolling
format: revealjs
engine: knitr
---

## Quarto

```{r}
#| class-output: hscroll

library(gapminder)
df <- dplyr::bind_cols(gapminder, gapminder, .name_repair = "minimal")

head(df)
```

```{css, echo=FALSE}
.hscroll {
  overflow-x: auto;
  white-space: nowrap;
}
```

<hr>

如何在 Quarto Reveal.js 演示中使代码块的输出在水平方向上可滚动?

<hr>

And if you want to do this for code chunks, instead of passing the .hscroll class as a chunk option to a specific chunk, use the knitr opts_chunk key in the yaml section.

---
title: Output Horizontal scrolling
format: revealjs
engine: knitr
knitr:
  opts_chunk: 
    class-output: hscroll
---

## Quarto

```{r}
library(gapminder)
df &lt;- dplyr::bind_cols(gapminder, gapminder, .name_repair = &quot;minimal&quot;)

head(df)
```

```{css, echo=FALSE}
.hscroll {
  overflow-x: auto;
  white-space: nowrap;
}
```

huangapple
  • 本文由 发表于 2023年2月16日 19:29:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定