1

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.

StatsStudent
  • 1,384
  • 2
  • 10
  • 28

1 Answers1

3

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
Julian
  • 6,586
  • 2
  • 9
  • 33
  • 1
    However, I would suggest using `::before`, instead of `:before` (see [here](https://stackoverflow.com/a/7327341/10858321) for details.) – shafee Apr 06 '23 at 13:57
  • Sadly (or maybe it's a good thing), this is the solution I already had. I was really hoping to be able to just add an option to the yaml header. The CSS can get more complicated too if I'm attempting to create more complex headers. Thanks for your help! – StatsStudent Apr 06 '23 at 14:00