如何在 r-markdown 中仅更改附录的章节/节/页编号模式而不破坏交叉引用?

Vas*_*ash 4 latex pandoc rstudio r-markdown bookdown

我正在使用 r-markdown (具体来说,bookdown)写一篇论文。论文的主要内容均使用阿拉伯数字进行编号,包括页、章、节和小节。

但是,我需要使用字母数字对章节进行附录编号,然后使用阿拉伯数字对章节和小节进行编号。页码也必须是字母数字。

我正在尝试得到这个:

A. Appendix
A.1. Section
A.1.1. Subsection
Run Code Online (Sandbox Code Playgroud)

而不是这个:

5. Appendix
5.1. Section
5.1.1. Subsection
Run Code Online (Sandbox Code Playgroud)

附录从第 页开始54,但是,我需要页码从 开始A

我已经按照我需要的方式进行了章节/页码编号,但是它破坏了我的目录和文档中的一些交叉引用。

我的主要 .rmd 文件如下:

---
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'}
'''

Run Code Online (Sandbox Code Playgroud)

此外,该文件的05-appendix.rmd开头如下:

# Appendix
\setcounter{page}{0}
\pagenumbering{Alph}
Run Code Online (Sandbox Code Playgroud)

这会创建如上所述的所需结果,但问题是它也会破坏指向附录章节或附录中任何部分的交叉引用。当我单击目录中的“附录”时,它会链接到位于 中的第 1 章01-intro.rmd。当我单击目录中附录下的某个部分时,它会转至第 1 章中的相应部分。

但是,子部分的链接按预期工作,链接到附录中的正确位置。

我认为重新开始附录的编号可能会导致 Latex/pandoc 混淆并链接到第 1 章,但我不知道为什么这会让各小节正常工作。

Vas*_*ash 5

解决方案相当简单。无需手动进行更改,例如将页码更改为alph,然后重置页数,然后重置章节数等 - 可以在 bookdown 项目中简单地使用“/backmatter”。在我上面的例子中,它看起来像这样:

---
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'}
'''
Run Code Online (Sandbox Code Playgroud)

在底部,您可以看到我最初的位置:

\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
Run Code Online (Sandbox Code Playgroud)

我现在已经替换为\backmatter. 这必须在将附录章节包含在我的 R Chunk 中之前完成,而不是从附录章节内部完成。使用附录文件执行此操作意味着附录的第一页/部分编号不正确,可能是因为 Knit 创建输出的顺序所致。