How to change width of HTML stargazer table?

I really like the style of the tables that the stargazer package uses. Tables are rendered in pdf using Knitr and Rstudio. However, when I try to knit my .Rmd into an html page, the tables eventually flatten. The Chunk option fig.widthdoes not help, and does not have the stargazer option column.sep.width. Is there a way to change the width of the table or is there another workflow to get pretty summary tables in html?

Playable example:

{r test, results = "asis"}

stargazer::stargazer(attitude,
                 type = "html",
                 digits = 2,
                 summary.stat = c("mean","sd","median","min", "max"))

Latex rendering

HTML rendering

+4
source share
2 answers

htmlTable::htmlTable, . htmlTable, , , , . , , , .

, css . , 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;')
```

enter image description here

+3

HTML . table, , .. , table <table style="text-align:center"> <table style="text-align:center" width="3000">

+1

Source: https://habr.com/ru/post/1654835/


All Articles