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

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

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

问题

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

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

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

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

提前感谢!

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

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!

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

答案1

得分: 3

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

第一个例子:

  1. .hscroll {
  2. overflow-x: auto;
  3. white-space: nowrap;
  4. }

第二个例子:

  1. knitr:
  2. opts_chunk:
  3. 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.

  1. ---
  2. title: Output Horizontal scrolling
  3. format: revealjs
  4. engine: knitr
  5. ---
  6. ## Quarto
  7. ```{r}
  8. #| class-output: hscroll
  9. library(gapminder)
  10. df <- dplyr::bind_cols(gapminder, gapminder, .name_repair = "minimal")
  11. head(df)
  12. ```
  13. ```{css, echo=FALSE}
  14. .hscroll {
  15. overflow-x: auto;
  16. white-space: nowrap;
  17. }
  18. ```

<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.

  1. ---
  2. title: Output Horizontal scrolling
  3. format: revealjs
  4. engine: knitr
  5. knitr:
  6. opts_chunk:
  7. class-output: hscroll
  8. ---
  9. ## Quarto
  10. ```{r}
  11. library(gapminder)
  12. df &lt;- dplyr::bind_cols(gapminder, gapminder, .name_repair = &quot;minimal&quot;)
  13. head(df)
  14. ```
  15. ```{css, echo=FALSE}
  16. .hscroll {
  17. overflow-x: auto;
  18. white-space: nowrap;
  19. }
  20. ```

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:

确定