How to set page break before each chapter in bookdown project?

What is an appropriate way to have a page break before each of my chapters in my bookdown project? edit: this is for a PDF output

In an Rmarkdown document I would just use \newpage, but that does not work for my bookdown project. In this project I have place \newpage at the end of my Rmd documents and at the beginning, but neither option worked.

  1. Should I set this in the index.Rmd? How?
  2. Should I set this in the _bookdown.yml? How?
  3. Should I set this in the _output.yml? How?

I would also appreciate it if you could direct me to references for:

  • bookdown
  • rmarkdown
  • yaml
  • LaTeX

I've reviewed the bookdown and rmarkdown stuff prepared by Yihui Xie, but I don't know where to go to find what I need to be able to understand the options.

My _bookdown.yml:

book_filename: my-book-filename
output_dir: _book
delete_merged_file: true
language:
  label:
      fig: "FIGURE "
      tab: "TABLE "
  ui:
    chapter_name: "Chapter "

My _output.yml:

bookdown::gitbook:
  css: style.css
  split_by: section
  config:
    toc:
      before: |
        <li>""</li>
      after: |
        <li>""</li>
    edit: ""
    download: ["pdf", "epub"]
bookdown::html_chapters:
  css: [css/style.css, css/toc.css]
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
  toc_depth: 3
  toc_appendix: yes
bookdown::epub_book: default

My index.Rmd:

---
title: "My Title"
author: "The Author"
date: "`r format(Sys.Date(), '%d %B %Y')`"
knit: "bookdown::render_book"
documentclass: report
bibliography: [book.bib]
link-citations: yes
colorlinks: yes
lot: no
lof: no
fontsize: 12pt
papersize: letter
site: bookdown::bookdown_site
description: "A brief description"
output:
  bookdown::gitbook:
    lib_dir: "book_assets"
---

Are you targeting a PDF output for this ?

For HTML book it is split according to the split_byoption for gitbook() and it is split by chapter for bs4_book().

Yes, in this case my target is a PDF - I should have stated that clearly.

Where are you inserting those \newpage line ?

It should be on its own line inside the Rmd document after the paragraph you want to go the the new page.
This is not a bookdown feature, it is a LaTeX thing and inserting raw TeX should be kept during the process, so it should work as long as it works in LaTeX

For example, at the beginning:

\newpage

# Mission {#mission}

And at the end,

## Quarter

- Quarterly reports

\newpage

But neither approach made it so that my chapter started with a new page.

edit: And thanks for sharing that link; I will review it.

I am not quite sure to follow why you need to add at the beginning or at the end of a chapter. bookdown::pdf_book() already split by chapter and you'll get a new page for each section. Don't you ?

I tried adding \newpage on the bookdown-demo book in between paragraph and it worked.

Maybe you can share a full reproducible example of what is not working for you based on GitHub - rstudio/bookdown-demo: A minimal book example using bookdown ?

Thank you. That bookdown demo is what I used to build this project. I made a (minimal reproducible example)[GitHub - reneherrera-cocohhs/my-bookdown-example] from my project, but I see that there is a page break occurring prior to each chapter, starting with the index.

I don't understand what might be or might have been the problem with my project that I was originally asking about.

1 Like

Glad it is working now !

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Yes, but I don't understand why it is working now. As far as I know, I did not make any changes. I still don't understand which project level settings to set in order to return a PDF with page breaks before each chapter.

bookdown offers bookdown::pdf_book() to write some PDF books following bookdown features and must be pair with a LaTeX documentclass: book in YAML (or another book-like class).
See

I believe the Book documentclass in LaTeX will by default make the newpage before each chapter. You should see about how that works in LaTeX.

I think I understand now. There are two setting I must set.

1

In the _output.yml file, set for example:

bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
  toc_depth: 3
  toc_appendix: yes

2

And in the index.Rmd file set, for example:

documentclass: book
1 Like

Yes documentclass: book is required in the index.Rmd in addition of the format you want to use. Sometimes, there are some specific documentclass like krantz that need to be set for book - that is why it is not hardcoded. However, this should be set in all the book template.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.