Reputation: 73
I have this table when I run this code in R. However the numbers are so close to each other, I was wondering if there is any way I could make the space gap bigger between them?
Code: Data %>% stargazer (type="html",title = " Summary statistics of the samples", align = TRUE, out="Variables Descriptive.html")
Upvotes: 1
Views: 785
Reputation: 18734
I couldn't find a way through the stargazer
function, but I found a workaround. I've included two ways to do this because I don't know if you're using this in RMD or using the file "Variables Descriptive.html". If you're using the HTML file in RMD (outside of R code), follow the instructions for modifying the HTML file.
Add the following before you get to the chunk that executes this table—not in a code chunk.
<style>
.myTable > table {
width: 75%;
}
</style>
Add the following immediately before the code chunk that executes the table add the following—not in a code chunk.
<div class="myTable">
Add the following immediately after the code chunk that executes the table—not in a code chunk.
</div>
It will look something like this:
---
title: "Untitled"
author: "me"
date: "2/24/2022"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(stargazer)
```
<style>
.myTable > table {
width: 75%;
}
</style>
<div class="myTable">
```{r cars, results="asis"}
stargazer(attitude, type = "html", align = T, header = F,
title = " Summary statistics of the samples",
out = "var.html")
```
<div>
After you see the output, you can adjust the width accordingly. Depending on the screen size, the width will change. However, this also ensures that the spacing is evenly dispersed.
You could use any text editor to open the file. I used the source pane of RStudio by going to the File tab, left-clicking on the name of the .HTML file, and selecting Open in Editor.
You will see the HTML code in your source pane now. The first tag is the table tag; that's what we're going to change.
Currently it states:
<table style="text-align:center">
You are going to add the inline CSS here. Add a semi-colon to the end of the inline styles in the code. In this example, I added a semi-colon after center
. Then add width: 75%;
. Make sure that you've not erased the closing parentheses or closing tag ">
.
Save the file. You can select Preview from the menu bar within the Source pane with this HTML code or you can go back to the File pane and View in Browser to see the changes. Just like before, the size of the viewing screen will change the size of the table.
Upvotes: 2