8

I cannot find out how to make a page break in R bookdown. With page break I mean that the content within one page is displayed as one website.

By default there is always a page break in front of every new section (like # Chapter 1). So, if I run render_book each section becomes one html file. But, if I have a lot of subsections then these sites get very long.

I would like to have page breaks before every subsection (like ## Chapter 1.1).

So far I tried adding \newpage, \pagebreak, --------------- to the .Rmd or to just provide the .Rmd files in the same structure as I would like to have them as .html files. Either way, the .html files are always created according to the sections.

mRcSchwering
  • 820
  • 8
  • 25

1 Answers1

6

I think this is specified by the split_by argument of gitbook as documented here.

Sounds like you are using chapter but you want to be using section

The split_by argument specifies how you want to split the HTML output into multiple pages, and its possible values are:

  • rmd: use the base filenames of the input Rmd files to create the HTML filenames, e.g., generate chapter3.html for chapter3.Rmd;
  • none: do not split the HTML file (the book will be a single HTML file);
  • chapter: split the file by the first-level headers;
  • section: split the file by the second-level headers;
  • chapter+number and section+number: similar to chapter and section, but the files will be numbered;
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • 1
    You can use it with `render_book()`. Output formats in bookdown are typically designed for `bookdown::render_book()`, and some also work with `rmarkdown::render()`. This answer applies to any output format function in bookdown that contains the `split_by` argument. – Yihui Xie Oct 11 '16 at 02:35
  • @Yihui that's good to know. I was surprised, the documentation of `render_book` doesn't mention the `split_by` argument, and even the `...` documentation is only for `preview_chapter`, nothing about what `render_book`'s `...` is passed on to. – Gregor Thomas Oct 11 '16 at 16:22
  • The help page `?bookdown::render_book` said `...` was passed to `rmarkdown::render()`. `split_by` is not an argument of `bookdown::render_book()` or `rmarkdown::render()`; it is an argument of `bookdown::gitbook`. – Yihui Xie Oct 12 '16 at 01:03
  • I know this is long ago, but you can set it as option in `_output.yml`: `split_by: section` in the `bookdown::gitbook:` part. – Revan Apr 20 '20 at 06:40