2

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: enter image description here

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);
}
jpsmith
  • 11,023
  • 5
  • 15
  • 36

1 Answers1

3

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;
}
```

horizontal scrolling in output in revealjs


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 <- dplyr::bind_cols(gapminder, gapminder, .name_repair = "minimal")

head(df)
```

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

shafee
  • 15,566
  • 3
  • 19
  • 47
  • Thank you so much, @shafee. The horizontal scrolling works. Highly appreciated. I tried to add a color and background option to the code like the one below but it does not work. Any possible reason why? Thanks, again! ```{css, echo=FALSE} .hscroll { overflow-x: auto; white-space: nowrap; color: #fff; background: rgb(131, 139, 139); } ``` – Chris_030500 Feb 16 '23 at 13:15
  • 1
    The reason its not working because the hscroll class is added for `pre` tag, but the code tag is using `#fff` as bg color. so `hscroll` can not override that. So in this case ideal option would be using sass variable. – shafee Feb 16 '23 at 13:31
  • 1
    Can you post a new question regarding this? I think a separate question and answer regarding code background would be more useful on this site : ). – shafee Feb 16 '23 at 13:31