如何更改 Stargazer HTML table 宽度?
How to change Stargazer HTML table width?
我真的很喜欢 stargazer 包使用的 tables 样式。 tables 使用 Knitr 和 Rstudio 在 pdf 中呈现良好。但是,当我尝试将我的 .Rmd 编入 html 页面时,table 最终被压在一起。块选项 fig.width
无济于事,观星者选项 column.sep.width
也无济于事。有什么方法可以更改 table 宽度,或者是否有另一个工作流程可以在 html 中获得漂亮的摘要 table?
可重现的例子:
{r test, results = "asis"}
stargazer::stargazer(attitude,
type = "html",
digits = 2,
summary.stat = c("mean","sd","median","min", "max"))
创建文件后,尝试进入文件中的实际 HTML。将有一个 table
标记来确定样式、宽度等。例如,如果 table
标签是 <table style="text-align:center">
,请手动将宽度设置为 <table style="text-align:center" width="3000">
我严重偏向htmlTable::htmlTable
,但我还是会加上这个。 htmlTable
,顾名思义,只是为了制作tables,所以不包括stargazer的所有花里胡哨,但这个功能有很多选项可以自定义输出。因此,您可能需要做额外的工作才能获得需要放入 table.
中的输出
与其他答案类似,您可以使用 css 来操纵 table 的样式。例如,您可以将 css 传递给 css.cell
:
---
output: html_document
---
```{r test, results='asis', include=FALSE}
stargazer::stargazer(attitude,
type = "html",
digits = 2,
summary.stat = c("mean","sd","median","min", "max"))
```
```{r}
## apply a list of functions to a list or vector
f <- function(X, FUN, ...) {
fn <- as.character(match.call()$FUN)[-1]
out <- sapply(FUN, mapply, X, ...)
setNames(as.data.frame(out), fn)
}
(out <- round(f(attitude, list(mean, sd, median, min, max)), 2))
```
```{r, results='asis'}
library('htmlTable')
htmlTable(out, cgroup = 'Statistic', n.cgroup = 5, caption = 'Table 1: default')
htmlTable(out, cgroup = 'Statistic', n.cgroup = 5, caption = 'Table 1: padding',
## padding to cells: top side bottom
css.cell = 'padding: 0px 10px 0px;')
```
以下 tables 用于无填充和两侧的额外填充
我真的很喜欢 stargazer 包使用的 tables 样式。 tables 使用 Knitr 和 Rstudio 在 pdf 中呈现良好。但是,当我尝试将我的 .Rmd 编入 html 页面时,table 最终被压在一起。块选项 fig.width
无济于事,观星者选项 column.sep.width
也无济于事。有什么方法可以更改 table 宽度,或者是否有另一个工作流程可以在 html 中获得漂亮的摘要 table?
可重现的例子:
{r test, results = "asis"}
stargazer::stargazer(attitude,
type = "html",
digits = 2,
summary.stat = c("mean","sd","median","min", "max"))
创建文件后,尝试进入文件中的实际 HTML。将有一个 table
标记来确定样式、宽度等。例如,如果 table
标签是 <table style="text-align:center">
,请手动将宽度设置为 <table style="text-align:center" width="3000">
我严重偏向htmlTable::htmlTable
,但我还是会加上这个。 htmlTable
,顾名思义,只是为了制作tables,所以不包括stargazer的所有花里胡哨,但这个功能有很多选项可以自定义输出。因此,您可能需要做额外的工作才能获得需要放入 table.
与其他答案类似,您可以使用 css 来操纵 table 的样式。例如,您可以将 css 传递给 css.cell
:
---
output: html_document
---
```{r test, results='asis', include=FALSE}
stargazer::stargazer(attitude,
type = "html",
digits = 2,
summary.stat = c("mean","sd","median","min", "max"))
```
```{r}
## apply a list of functions to a list or vector
f <- function(X, FUN, ...) {
fn <- as.character(match.call()$FUN)[-1]
out <- sapply(FUN, mapply, X, ...)
setNames(as.data.frame(out), fn)
}
(out <- round(f(attitude, list(mean, sd, median, min, max)), 2))
```
```{r, results='asis'}
library('htmlTable')
htmlTable(out, cgroup = 'Statistic', n.cgroup = 5, caption = 'Table 1: default')
htmlTable(out, cgroup = 'Statistic', n.cgroup = 5, caption = 'Table 1: padding',
## padding to cells: top side bottom
css.cell = 'padding: 0px 10px 0px;')
```
以下 tables 用于无填充和两侧的额外填充