我正在使用R Markdown生成一份报告,其中包含一个数据表格。我希望生成的html保持一些边距,而不是让表格占据整个页面宽度。
我尝试了包括以下内容:
knitr::opts_chunk$set(fig.width=5, fig.height=8)
我尝试过这个:
``` {r fig1, fig.height = 3, fig.width = 5, echo = FALSE, include=TRUE}
我尝试在输出的头部定义图像大小,也尝试在数据表本身的列宽选项上进行调整。
有什么建议吗?
这是一个Rmd示例:
---
title: "Initial Data Check Report"
date: "`r format(Sys.time(), '%B %d, %Y %H:%M:%S', 'America/Chicago', T)`"
output:
html_document:
self_contained: yes
theme: null
highlight: null
mathjax: null
params:
client: "ClientName"
---
### Audit Table
Some text here
---
```{r table, echo = FALSE, include=FALSE}
library(dplyr)
library(DT)
data = mtcars
```
``` {r fig1, fig.height = 3, fig.width = 5, echo = FALSE, include=TRUE}
datatable(data)
```
datatable(data, options = list(scrollX = '300px'))
。查找scrollX选项。如果表格溢出您设置的宽度,则会出现滚动条,否则不会。 - Lodewic Van Twillert