13.8 PDF via knitr/R Markdown

Without changing anything in Example 1 and Knitting it into a PDF, we get 13.3A.

Again, most of it already looks pretty good, but some parts over-run the page and the plot is not a good size.

We can fix the plot in exactly the same way we did for the Word version (fig.width), but the second table that is too wide needs some special handling. For this we use kable_styling(font_size=8) from the kableExtra package. Remember to install it when using for the first time, and include library(knitExtra) alongside the other library lines at the setup chunk.

We will also alter the margins of your page using the geometry option in the preamble as the default margins of a PDF document coming out of R Markdown are a bit wide for us.

Knitting to Microsoft Word from R Markdown. Before (A) and after (B) adjustment.

FIGURE 13.3: Knitting to Microsoft Word from R Markdown. Before (A) and after (B) adjustment.

The result is shown in Figure 13.3B.