1

If I am not mistaken, the font size argument in stargazer is ignored in rmarkdown documents:

Does somebody know how to fix this? See also here How to resize tables generated by Stargazer in R Markdown?

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("stargazer")
m <- lm(speed~dist, cars)
```

```{r, results='asis'}
stargazer(m, type = "html", font.size="tiny", single.row = T)
stargazer(m, type = "html", font.size="Huge", single.row = T)
```

```{r, results='asis'}
print(stargazer(m, type = "html", single.row = T), scalebox='0.7')
```
desval
  • 2,345
  • 2
  • 16
  • 23

3 Answers3

1

Just add this to the end of your YAML, adjusting the font size as you wish:

---
title: "Untitled"
output: html_document
---
<style>
body { font-size: 20px; }
</style>

And the larger font will render:

enter image description here

mysteRious
  • 4,102
  • 2
  • 16
  • 36
  • sorry, i wasnt clear, I just need to change the size of the table, not of the whole document – desval May 02 '20 at 21:17
1

I think that the font.size argument in stargazer is only used when rendered in Latex.

Instead when rendering to HTML you have to add a style element to the appropriate tag, in this case td for the table cell, th for the table header, or table for the entire table.

After the YAML header add the following css:

<style>

table, th, td {
    font-size: 16px;
}

</style>

Or, if you want e.g. large table headers:


<style>

th {
    font-size: 42px;
}

td {
    font-size: 21px;
}
</style>

o_v
  • 112
  • 8
0

Since the output is html it is necessary to have some knowledge about handling tables in html you can see here, so place the code <font size="5" face="Courier New" > at the top of the table.

enter image description here

---
title: "Untitled"
output: html_document
---

```{r cars, include=F}
library(stargazer)
stargazer(cars, type = "html", out="test.html", out.header=TRUE)
```
<font size="5" face="Courier New" >
<table style="text-align:center"><tr><td colspan="8" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Statistic</td><td>N</td><td>Mean</td><td>St. Dev.</td><td>Min</td><td>Pctl(25)</td><td>Pctl(75)</td><td>Max</td></tr>
<tr><td colspan="8" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">speed</td><td>50</td><td>15.400</td><td>5.288</td><td>4</td><td>12</td><td>19</td><td>25</td></tr>
<tr><td style="text-align:left">dist</td><td>50</td><td>42.980</td><td>25.769</td><td>2</td><td>26</td><td>56</td><td>120</td></tr>
<tr><td colspan="8" style="border-bottom: 1px solid black"></td></tr></table>
cdcarrion
  • 574
  • 6
  • 22