Spaces between columns in stargazer type = "html" table output
Asked Answered
W

2

10

I`m searching for a method (or alternative) to get spaces between the columns of an stargazer html-table output.

As

stargazer::stargazer(mtcars, type = "html")

results in

enter image description here

which is not very good to read...

Thank´s in advance!

Samuel

Wordplay answered 15/9, 2015 at 14:36 Comment(2)
I don't see any stargazer options that would allow this. I would edit the output file and add cellpadding=5 to the html table tagGaia
There's a 'column.sep.width' argument, but I think it only works for latex tables not HTML. :(Manager
D
4

If you are writing an RMarkdown document, you can customize your HTML tables using stylesheets.

This can be done adding the option CSS to your YAML header. Something like this:

---
title: "My HTML Doc"
output:
  html_document:
    css: styles.css
---

To increase the spacing between columns you could, for example, add some padding to the left of the cells. So, in your styles.css files you could put something like:

th, td {
    padding-left: 10px;
    text-align: left;        
}

For further information about using CSS in RMarkdown, please check this. For more about CSS for HTML tables, please check this.

Deibel answered 12/1, 2017 at 6:53 Comment(0)
H
5

You can also drop the CSS directly into the RMarkdown document (see here). eg.

---
title: "Untitled"
author: "Author"
date: "29 June 2017"
output: html_document
---

```{css, echo = FALSE}

table, td, th {
  border: none;
  padding-left: 1em;
  padding-right: 1em;
  margin-left: auto;
  margin-right: auto;
  margin-top: 1em;
  margin-bottom: 1em;
}

```


```{r, results = "asis"}

stargazer::stargazer(mtcars, type = "html")

```
Hildy answered 29/6, 2017 at 5:9 Comment(0)
D
4

If you are writing an RMarkdown document, you can customize your HTML tables using stylesheets.

This can be done adding the option CSS to your YAML header. Something like this:

---
title: "My HTML Doc"
output:
  html_document:
    css: styles.css
---

To increase the spacing between columns you could, for example, add some padding to the left of the cells. So, in your styles.css files you could put something like:

th, td {
    padding-left: 10px;
    text-align: left;        
}

For further information about using CSS in RMarkdown, please check this. For more about CSS for HTML tables, please check this.

Deibel answered 12/1, 2017 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.