如何使RMarkdown代码块中出现垂直滚动条(html视图)

时间:2023-01-17 06:03:58

I've found many examples outlining how to add horizontal scrollbars to R Markdown HTML output, including this specific example here. However, none that describe how to add vertical scrollbars. Again borrowing from the linked example, but transposing a wide matrix to a "tall" matrix, I'd like to scroll vertically through the matrix in my ioslide presentation.

我发现了许多示例,概述了如何将水平滚动条添加到R Markdown HTML输出,包括此处的具体示例。但是,没有一个描述如何添加垂直滚动条。再次借用链接的示例,但将宽矩阵转换为“高”矩阵,我想在我的ioslide演示文稿中垂直滚动矩阵。

---
title: "Vertical needs"
author: "Hyped"
date: "December 13, 2016"
output: ioslides_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Where's my vertical scrollbar?

```{r}
x <- matrix(nrow = 40, ncol = 4, data = 1)
x
```

The output of the above matrix extends to the bottom edge of the slide and then vanishes. No scrollbar. I tried modifying the answers given for solving the lack of horizontal scrollbars by modifying the CSS style code added to the .Rmd file (or placed in a custom CSS) from

上述矩阵的输出延伸到幻灯片的下边缘然后消失。没有滚动条。我尝试通过修改添加到.Rmd文件(或放置在自定义CSS)中的CSS样式代码来修改为解决缺少水平滚动条而给出的答案

<style>
pre code, pre, code {
  white-space: pre !important;
  overflow-x: scroll !important;
  word-break: keep-all !important;
  word-wrap: initial !important;
}
</style>

to (swapping overflow-x to overflow-y):

to(将overflow-x交换为overflow-y):

<style>
pre code, pre, code {
  white-space: pre !important;
  overflow-y: scroll !important;
  word-break: keep-all !important;
  word-wrap: initial !important;
}
</style>

but no luck. Can anyone provide the missing piece of the puzzle?

但没有运气。任何人都可以提供拼图的缺失部分吗?

1 个解决方案

#1


1  

The problem seems to be that you did not specify the height of the code chunk. Try this instead:

问题似乎是你没有指定代码块的高度。试试这个:

<style>
pre {
  white-space: pre !important;
  overflow-y: scroll !important;
  height: 50vh !important;
}
</style>

(For information about the unit vh check this)

(有关单位的信息,请检查)

如何使RMarkdown代码块中出现垂直滚动条(html视图)

#1


1  

The problem seems to be that you did not specify the height of the code chunk. Try this instead:

问题似乎是你没有指定代码块的高度。试试这个:

<style>
pre {
  white-space: pre !important;
  overflow-y: scroll !important;
  height: 50vh !important;
}
</style>

(For information about the unit vh check this)

(有关单位的信息,请检查)

如何使RMarkdown代码块中出现垂直滚动条(html视图)