首页 > 解决方案 > 如何在 markddown 中调整 R 输出表的大小?

问题描述

我一直在寻找时间在降价时调整表格大小,以免损坏。我想过减少源或强制它不中断,但我该怎么做呢?我只找到了使用 kable 或 kableextra 的解决方案,但是我想要默认样式。我将数据留在了网址中。

数据

在此处输入图像描述

标签: ryamlr-markdownmarkdownknitr

解决方案


我们可以改变widthin options。检查电流width并进行这些更改

> head(cbind(iris, iris, iris))
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length
1          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4
2          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4
3          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3
4          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5
5          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4
6          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7
  Petal.Width Species
1         0.2  setosa
2         0.2  setosa
3         0.2  setosa
4         0.2  setosa
5         0.2  setosa
6         0.4  setosa
> op <- options()
> options()$width # check the current width
[1] 167
> options(width = 300) # change the width and now do the print again
> head(cbind(iris, iris, iris))
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa

options完成后,再次重置

> options(op)
> options()$width
[1] 167

推荐阅读