Skip to content

rmarkdown and font size

2 messages · MacQueen, Don, Nordlund, Dan (DSHS/RDA)

#
Suppose I have a file (named "tmp.rmd") containing:


---
title: Test
---

```{r example, echo=FALSE, results='asis'}
tmp <- data.frame(a=1:5, b=letters[1:5])
print( knitr::kable(tmp, row.names=FALSE))
```



And I render it with:

rmarkdown::render('tmp.rmd', output_format=c('html_document','pdf_document'))

I get two files:
  tmp.pdf
  tmp.html

Is there a way to control (change or specify) the font size of the table in the pdf output?
(or of the entire document, if it can't be changed for just the table)

With my actual data, the table is too wide to fit on a page in the pdf output; perhaps if I reduce the font size I can get it to fit.

I would like the html version to still look decent, but I don't care very much what happens to its font size.

Thanks!
-Don
#
You can change the style, modifying a variety of things.  E.g,

---
title: Test
---

<style type="text/css">

body{ /* Normal  */
      font-size: 12px;
  }
td {  /* Table  */
  font-size: 8px;
}
h1.title {
  font-size: 38px;
  color: DarkRed;
}
h1 { /* Header 1 */
  font-size: 28px;
  color: DarkBlue;
}
h2 { /* Header 2 */
    font-size: 22px;
  color: DarkBlue;
}
h3 { /* Header 3 */
  font-size: 18px;
  font-family: "Times New Roman", Times, serif;
  color: DarkBlue;
}
code.r{ /* Code block */
    font-size: 12px;
}
pre { /* Code block - determines code spacing between lines */
    font-size: 14px;
}
</style>

Here is some normal text.  It is a 12-point font.  The table is in 8-point . 
  
```{r example, echo=FALSE, results='asis'}
tmp <- data.frame(a=1:5, b=letters[1:5])
print( knitr::kable(tmp, row.names=FALSE))
```


Hope this is helpful,

Dan

Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services