1

What are my options for changing the font size of dynamically-generated output, when rendering to a PDF? My document currently looks something like this:

---
title: "Foo"
author: "Bar"
date: "`r format(Sys.time(), '%B %e, %Y')`"
output:
  pdf_document: default
  html_document:
    df_print: paged
header-includes: \usepackage{amsmath} \usepackage{color}
---

# Introduction

```{bash echo=FALSE}
perl -le 'print for 1..50'
```

I want to decrease the font size to help more output fit on a single page of the PDF. I'm not currently also outputting to HTML, so a cross-format solution would be cool but not really necessary.

Ken Williams
  • 22,756
  • 10
  • 85
  • 147

1 Answers1

3

It is as simple as fontsize: 12pt (or of course fontsize: 9pt as we use in pinp)

Modified file:

---
title: "Foo"
author: "Bar"
date: "`r format(Sys.time(), '%B %e, %Y')`"
fontsize: 12pt
output:
  pdf_document: default
  html_document:
    df_print: paged
header-includes: \usepackage{amsmath} \usepackage{color}
---

# Introduction

```{bash echo=FALSE}
perl -le 'print for 1..50'
```

If you want it just for code / result snippets I would suggested you place appropriate \begin{Large} and \end{Large} around it. I have in the past customized the default environments used here --- as I recall knitr more or less follows Sweave here. Just look at the generated .tex file.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Aha, the `\begin{size}` mechanism should work well for me, thanks. – Ken Williams Feb 16 '18 at 04:48
  • Actually, I haven't gotten the size environment to work. It seems to remove the `verbatim` environment, then that causes syntax errors for LaTeX. However, I can do something similar by using `\small ... \normalsize` around my code/result snippet. – Ken Williams Feb 16 '18 at 05:30
  • Try peeking at the generated .tex file and look for the "framed" environment. I keep seeing hints that eg `fontsize=small` can be added. Sorry, don't seem to have a ready-example I can quote from. – Dirk Eddelbuettel Feb 16 '18 at 14:56