1 Introduction

1.1 Figure nameing and rendering

To auto name figures and store them in an organized fashion we do the following

  • make setup chunk for each chapter (at beginning of chapter)
  • name a target directory in fig after the chapter
knitr::opts_chunk$set(fig.path = "fig/0100-intro/", dev = "png")

Then when we make a plot (Figure 1.1) we don’t need to explicitly save it, name it or read it back in with that name for it to render when served online. Stored in a rational place with a meaningful name for easy recovery. Another gotcha is that we need to set the caption for the plot with fig.cap= to have the cross referencing work.

my_caption <- "Example of plot figure generated with knitr opts chunk."
ggplot2::ggplot(data = mtcars, ggplot2::aes(x = mpg, y = hp)) +
  ggplot2::geom_point()
Example of plot figure generated with knitr opts chunk.

Figure 1.1: Example of plot figure generated with knitr opts chunk.

knitr::include_graphics("fig/0100-intro/Screenshot 2025-03-14 at 12.50.06 PM.png")

1.2 Conditional Formating for pdf vs gitbook

Line Breaks

Here is an example of how to insert an empty line between paragraphs. We do it using two blank lines…

This is the paragraph that follows the empty line.

Additionally, writers should investigate the impacts of different header levels (ex. First level (#) or Second level (##) or third (###)) as well as before and after figures/tables on spacing before and after the headers so we produce as professional looking documents as possible. There are idiosyncrasies with what happens for each above and below so that should be tested by building the documents in both formats (html and pdf) and viewing the output. Here is a test with a second level header with no empty line above and no empty line below. ## Header with no number {-}

It negates the header… wow.

If we put blank lines above the header however…

1.3 Another numbered Header

No spacing or <br> above this line.

Here is a fpr_kable with a cross reference to Table 1.2.

knitr::kable(
  head(iris, 10), caption = 'Here is a nice kable!',
  booktabs = TRUE
)
Table 1.1: Here is a nice kable!
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa

This is what happens with multiple empty lines but no <br> inserted directly after a figure…

head(iris, 20) %>% 
  fpr::fpr_kable(
  caption_text = 'Here is a fpr_kable with no cross-ref and the scroll set to not happen when pdf built.',
  scroll = params$gitbook_on)
Table 1.2: Here is a fpr_kable with no cross-ref and the scroll set to not happen when pdf built.
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa
5.4 3.7 1.5 0.2 setosa
4.8 3.4 1.6 0.2 setosa
4.8 3.0 1.4 0.1 setosa
4.3 3.0 1.1 0.1 setosa
5.8 4.0 1.2 0.2 setosa
5.7 4.4 1.5 0.4 setosa
5.4 3.9 1.3 0.4 setosa
5.1 3.5 1.4 0.3 setosa
5.7 3.8 1.7 0.3 setosa
5.1 3.8 1.5 0.3 setosa


But if we put a <br> below the figure with blank lines either side of our text we are good to go.

Test.