如何在不破坏交叉引用的情况下仅更改 r-markdown 中附录的 chapter/section/page 编号模式?
How to change chapter/section/page numbering schema for just Appendix in r-markdown without breaking cross references?
我正在使用 r-markdown(特别是 bookdown)写一篇论文。论文正文全部采用阿拉伯数字编号,包括页、章、节、小节。
但是,我需要为章节使用字母数字对附录进行编号,然后为节和小节使用阿拉伯数字。页码也必须是字母数字。
我想得到这个:
A. Appendix
A.1. Section
A.1.1. Subsection
而不是这个:
5. Appendix
5.1. Section
5.1.1. Subsection
附录从第 54
页开始,但是,我需要页码从 A
重新开始。
我已经得到了我需要的 Chapter/Page 编号,但是它破坏了我的 table 内容和文档中的一些交叉引用。
我的主要 .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'}
'''
另外,文件 05-appendix.rmd
的开头是这样的:
# Appendix
\setcounter{page}{0}
\pagenumbering{Alph}
如上所述,这将创建所需的结果,但问题是它还破坏了指向附录章节或附录中任何部分的交叉引用。当我点击目录table中的"Appendix"时,它link转到位于01-intro.rmd
的第1章。当我单击目录中附录下的某个部分时,它会转至第 1 章中的相应部分。
但是,子部分的link按预期工作,link在附录中的适当位置。
我想也许重新开始为附录编号会导致 latex/pandoc 混淆并 link 到第 1 章,但我不知道为什么这会使小节正常工作。
解决方案相当简单。与其手动进行更改,例如将页码更改为 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'}
'''
在底部,您可以看到我最初的位置:
\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
我现在换成了\backmatter
。这必须在我的 R Chunk 中包含附录章节之前完成,而不是从 inside 附录章节。使用附录文件执行此操作意味着附录的第一个 page/section 编号不正确,可能是因为 Knitr 创建输出的顺序。
我正在使用 r-markdown(特别是 bookdown)写一篇论文。论文正文全部采用阿拉伯数字编号,包括页、章、节、小节。
但是,我需要为章节使用字母数字对附录进行编号,然后为节和小节使用阿拉伯数字。页码也必须是字母数字。
我想得到这个:
A. Appendix
A.1. Section
A.1.1. Subsection
而不是这个:
5. Appendix
5.1. Section
5.1.1. Subsection
附录从第 54
页开始,但是,我需要页码从 A
重新开始。
我已经得到了我需要的 Chapter/Page 编号,但是它破坏了我的 table 内容和文档中的一些交叉引用。
我的主要 .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'}
'''
另外,文件 05-appendix.rmd
的开头是这样的:
# Appendix
\setcounter{page}{0}
\pagenumbering{Alph}
如上所述,这将创建所需的结果,但问题是它还破坏了指向附录章节或附录中任何部分的交叉引用。当我点击目录table中的"Appendix"时,它link转到位于01-intro.rmd
的第1章。当我单击目录中附录下的某个部分时,它会转至第 1 章中的相应部分。
但是,子部分的link按预期工作,link在附录中的适当位置。
我想也许重新开始为附录编号会导致 latex/pandoc 混淆并 link 到第 1 章,但我不知道为什么这会使小节正常工作。
解决方案相当简单。与其手动进行更改,例如将页码更改为 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'}
'''
在底部,您可以看到我最初的位置:
\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
我现在换成了\backmatter
。这必须在我的 R Chunk 中包含附录章节之前完成,而不是从 inside 附录章节。使用附录文件执行此操作意味着附录的第一个 page/section 编号不正确,可能是因为 Knitr 创建输出的顺序。