3
votes

I'm writing a thesis paper using r-markdown (specifically, bookdown). The main-matter of the paper is all numbered using arabic numerals, including pages, chapters, sections, and subsections.

However, I need to have the appendix numbered using alpha numerals for the chapter, followed by arabic numerals for sections and subsections. Page numbers also need to be alpha numerals.

I am trying to get this:

A. Appendix
A.1. Section
A.1.1. Subsection

Instead of this:

5. Appendix
5.1. Section
5.1.1. Subsection

The Appendix begins on page 54, however, I need page numbers to restart at A.

I've gotten the Chapter/Page numbering to the way I need it to be, but it's breaking my table of contents and some of the cross references in the documents.

My main .rmd file is given here:

---
title: "My Title"
author: My Name
date: Aug 2019
output:
  bookdown::pdf_book:
    base_format: rmarkdown::pdf_document
    latex_engine: xelatex
    number_sections: yes
    toc: yes
    toc_depth: 5
    includes:
      in_header: ./tex/preamble.tex
      before_body: ./tex/cover.tex
  bookdown::word_document2:
    toc: yes
    toc_depth: 5
lof: true
lot: true
fontsize: 11pt
geometry:
  - top=1in
  - bottom=1in
  - left=1.5in
  - right=1.5in
documentclass: scrbook
papersize: letter
pagestyle: plain
bibliography: references.bib
csl: american-chemical-society.csl
classoption:
  - oneside
spacing: onehalfspacing
always_allow_html: yes
knit: (function(inputFile, encoding) {
  rmarkdown::render(inputFile, encoding = encoding,
  output_dir = "output", output_format = "all") })
---

'''{r child = '/chapters/00-abstract.rmd'}
'''

'''{r child = '/chapters/01-intro.rmd'}
'''

...

# References

<div id="refs"></div>

\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}

'''{r child = '/chapters/05-appendix.rmd'}
'''

Also, the file 05-appendix.rmd begins as such:

# Appendix
\setcounter{page}{0}
\pagenumbering{Alph}

This creates the desired results as described above, but the problem is that it also breaks cross references pointing to the Appendix chapter or any of the sections within the appendix. When I click "Appendix" in the table of contents, it links to the Chapter 1, located in 01-intro.rmd. When I click one of the sections under Appendix in the toc, it goes instead to the corresponding section in Chapter 1.

However, the links to the subsections work as expected, linking to their proper place in the appendix.

I thought that maybe restarting the numbering for the Appendix was causing latex/pandoc to get confused and link to chapter 1, but I don't know why that would leave subsections working properly.

1
Have you tried with only one of the changes in place? Have you tried \backmatter instead of changing chapter numbering by hand?Ralf Stubner
Do you have an example of a LaTeX document which follows this pattern? This is mostly a LaTeX issue, so if you have one that works, you should be able to import the same formatting into your bookdown document.user2554330
@RalfStubner I can't believe I didn't come across using just \backmatter.... that worked like a charm! Thank you so much.Vash
You are welcome. How about adding your solution as an answer?Ralf Stubner

1 Answers

4
votes

The solution was fairly simple. Rather than manually making the changes, such as changing page numbers to alph, then resetting the page count, then resetting the chapter count, etc--it is possible to simply use `/backmatter' in a bookdown project. In my example above, it would look like this:

---
title: "My Title"
author: My Name
date: Aug 2019
output:
  bookdown::pdf_book:
    base_format: rmarkdown::pdf_document
    latex_engine: xelatex
    number_sections: yes
    toc: yes
    toc_depth: 5
    includes:
      in_header: ./tex/preamble.tex
      before_body: ./tex/cover.tex
  bookdown::word_document2:
    toc: yes
    toc_depth: 5
lof: true
lot: true
fontsize: 11pt
geometry:
  - top=1in
  - bottom=1in
  - left=1.5in
  - right=1.5in
documentclass: scrbook
papersize: letter
pagestyle: plain
bibliography: references.bib
csl: american-chemical-society.csl
classoption:
  - oneside
spacing: onehalfspacing
always_allow_html: yes
knit: (function(inputFile, encoding) {
  rmarkdown::render(inputFile, encoding = encoding,
  output_dir = "output", output_format = "all") })
---

'''{r child = '/chapters/00-abstract.rmd'}
'''

'''{r child = '/chapters/01-intro.rmd'}
'''

...

# References

<div id="refs"></div>

\backmatter

'''{r child = '/chapters/05-appendix.rmd'}
'''

Towards the bottom, you can see that where I initially had:

\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}

I have now replaced with \backmatter. This had to be done before including the appendix chapter in my R Chunk rather that from inside the appendix chapter. Doing it withing the appendix file(s) means that the first page/section of the appendix is not properly numbered, possibly because of the order in which Knitr creates the output.