StatsStudent
StatsStudent

Reputation: 1604

How to insert the word "Chapter" followed by the chapter number in a Quarto book?

I am attempting to create an HTML book in RStudio using Quarto. I have set up each chapter of the book as a separate .qmd file and have all the chapters listed in my _quarto.yml file. By default, Quarto formats chapter headings as "X MyTitle" where X is the chapter number (e.g. 1, 2, 3, ...) and MyTitle is the heading (h1) (defined by # MyTitle at the beginning of each chapter's .qmd file). I would like to change this behavior so that each Chapter is automatically numbered and displayed as "Chapter X: MyTitle." This was straight forward when using knitr with bookdown by modifying the yaml file to include something like:

   book_filename: "machine-learning-causal-inference-with-bookdown"
   language:
     ui:
       chapter_name: "Chapter "

However, this does not appear to be valid in Quarto now (I tried this and it didn't work, nor do the options seem to be recognized by the IntelliSense/autocompletion in R Studio's IDE). I reviewed the quarto book options, but couldn't find an easy way to "restructure" the way the chapter headers are presented. I had hoped to replicate code from a sample Quarto book that had modified chapter headings, but sadly, all the examples provided in the documentation point to books that use the default chapter heading implementation (e.g. R for Data Science, Python for Data Analysis, and Visualization Curriculum).

So does anyone know a relatively straight forward way to accomplish this? If not, I figured, I can probably accomplish this, albeit somewhat painfully, with a custom Cascading Style Sheet (CSS) file, but given how common my desired chapter heading customization likely is, I can't imagine there's not already a simple and straight-forward way for handling this in Quarto.

Upvotes: 1

Views: 686

Answers (1)

Julian
Julian

Reputation: 9290

You could add this to your css file:

.chapter-number::before {
  content: "Chapter: ";
}

You can customize your chapter names in the YAML like this btw:

  chapters:
    - text: "My very own chapter name"
      file: 01-chapter.qmd

Upvotes: 3

Related Questions