Search code examples
rpdflatexknitrquarto

Different page numbers for `frontmatter` and `mainmatter` of book in quarto pdf format


I need to obtain separate page numbers for the frontmatter and mainmatter sections of a book in the format. I have the following YAML code in my _quarto.yml file. I'm curious about the approach to achieve this.

project:
  type: book

execute:
  echo: false
  warning: false
  
book:
  title: "Title"
  author: "Author"
  chapters:
    - index.qmd
    - Ch01.qmd
    - Ch02.qmd
    - references.qmd

bibliography: references.bib

format:
  pdf:
    documentclass: scrreprt
    toc: true
    toc-depth: 3
    lof: true
    lot: true

Solution

  • Use the \pagenumbering{<style>} command, where the <style> could be one of,

    • arabic: use Arabic numerals (1, 2, 3, ...)
    • roman: use lowercase roman numerals (i, ii, iii, ...)
    • Roman: use uppercase roman numerals (I, II, III, ...)
    • alph: use lowercase letters (a, b, c, ...)
    • Alph: use uppercase letters (A, B, C, ...)

    So to get Roman page-numbering up to the Ch01, use \pagenumbering{Roman} using include-before-body which starts Roman page-numbering just after the title page. And then at the top of Ch01.qmd use \pagenumbering{arabic} to reset the page-numbering in arabic numerals.

    project:
      type: book
    
    execute:
      echo: false
      warning: false
      
    book:
      title: "Title"
      author: "Author"
      chapters:
        - index.qmd
        - Ch01.qmd
        - Ch02.qmd
        - references.qmd
    
    bibliography: references.bib
    
    format:
      pdf:
        documentclass: scrreprt
        toc: true
        toc-depth: 3
        lof: true
        lot: true
        include-before-body: 
          text: |
            \pagenumbering{Roman}
          
    

    Ch01.qmd

    \pagenumbering{arabic}
    
    # Introduction
    
    This is a book created from markdown and executable code.
    
    See @knuth84 for additional discussion of literate programming.