R:更改 Rmd 中整个数据表的宽度

R: Change width of entire datatable in Rmd

我正在使用包含数据的 R markdown 生成报告table。我希望结果 html 保持一些边距,而不是 table 填充页面的整个宽度。

我试过包括:

knitr::opts_chunk$set(fig.width=5, fig.height=8) 

我试过这个:

 ``` {r fig1, fig.height = 3, fig.width = 5, echo = FALSE, include=TRUE}

我尝试在输出下的 header 中定义图形大小。我在数据 table 本身中使用了列宽选项。

有什么建议吗?

这是一个示例 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)

```

想要

<div style = "width:80%; height:auto; margin: auto;">
``` {r fig1, echo = FALSE, include=TRUE}
datatable(data)
```
</div>

工作?