css - xaringan 幻灯片上的水平滚动输出

标签 css xaringan remarkjs

我希望在水平滚动框中显示 R 命令的输出。代表:

library(ggplot2movies)
head(movies)
#                      title year length budget rating votes   r1   r2  r3   r4   r5   r6   r7   r8   r9  r10 mpaa Action Animation Comedy Drama Documentary Romance Short
# 1                        $ 1971    121     NA    6.4   348  4.5  4.5 4.5  4.5 14.5 24.5 24.5 14.5  4.5  4.5           0         0      1     1           0       0     0
# 2        $1000 a Touchdown 1939     71     NA    6.0    20  0.0 14.5 4.5 24.5 14.5 14.5 14.5  4.5  4.5 14.5           0         0      1     0           0       0     0
# 3   $21 a Day Once a Month 1941      7     NA    8.2     5  0.0  0.0 0.0  0.0  0.0 24.5  0.0 44.5 24.5 24.5           0         1      0     0           0       0     1
# 4                  $40,000 1996     70     NA    8.2     6 14.5  0.0 0.0  0.0  0.0  0.0  0.0  0.0 34.5 45.5           0         0      1     0           0       0     0
# 5 $50,000 Climax Show, The 1975     71     NA    3.4    17 24.5  4.5 0.0 14.5 14.5  4.5  0.0  0.0  0.0 24.5           0         0      0     0           0       0     0
# 6                    $pent 2000     91     NA    4.3    45  4.5  4.5 4.5 14.5 14.5 14.5  4.5  4.5 14.5 14.5           0         0      0     1           0       0     0

如何使输出在 xaringan 幻灯片上水平滚动?

最佳答案

@Yihui Xie 已经在 Github 上给出了很好的答案。我只是把它变成一个工作示例。需要注意的是:

1) 可以在 Rmarkdown 中将 css 指定为代码块,或者可以按照以下准则编写自己的 css 文件:https://github.com/yihui/xaringan/wiki .我假设这是一次性的事情,因此为简单起见,我将 css 包含在 Rmd 文件中。

2) pre元素设置属性后,还需要将width选项或R设置大一点,否则head 将为您包装输出。

---
title: "Horizontal scroll for wide output"
output:
  xaringan::moon_reader:
    css: ["default"]
    nature:
      highlightLines: true
---

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

```{css, echo=FALSE}
pre {
  background: #FFBB33;
  max-width: 100%;
  overflow-x: scroll;
}
```

```{r}
library(ggplot2movies)
op <- options("width"=250) # large number to trick head, otherwise see next slide
head(movies)
options(op) # set options back to default
```

---

```{r}
head(movies) # head with default width, note text gets wrapped. Though you can still scroll horizontally, as an effect of setting `pre`
```

关于css - xaringan 幻灯片上的水平滚动输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50919104/

相关文章:

css - 在 xaringan rmarkdown 中使用 css 将文本居中放置在标题幻灯片的标题中

html - 为什么@media (max-device-width : 360px) affected by the @media (max-device-width: 1024px)?

jquery - 如何使用 htmlService 定位 jQuery 对话框

html - 如何修复 css 导航闪烁问题

php - 如何防止 WordPress 在 WYSIWYG 编辑器中向元素添加额外的类

r - 是否有直接在代码中增加 Xaringan 幻灯片的快捷方式?

r - 在xaringan中使用特定的幻灯片编号作为slideNumberFormat

html - 如何在 Xaringan 演示文稿中调整图像大小?

r - 如何在 DT::datatable() 中搜索时停止 xaringan 的键盘快捷键?