我正在使用 r-markdown(特别是 bookdown)写论文。论文的主要内容全部使用阿拉伯数字编号,包括页、章、节和小节。
但是,我需要在附录中使用字母数字为章节编号,然后为节和小节使用阿拉伯数字。页码也需要是字母数字。
我想得到这个:
A. Appendix
A.1. Section
A.1.1. Subsection
取而代之的是:
5. Appendix
5.1. Section
5.1.1. Subsection
附录从
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'}
'''
此外,文件
05-appendix.rmd
开始是这样的:# Appendix
\setcounter{page}{0}
\pagenumbering{Alph}
这会创建如上所述的预期结果,但问题是它还会破坏指向附录章节或附录中任何部分的交叉引用。当我单击目录中的“附录”时,它会链接到位于
01-intro.rmd
中的第 1 章。 .当我单击目录中附录下的某个部分时,它会转到第 1 章中的相应部分。但是,到小节的链接按预期工作,链接到它们在附录中的适当位置。
我认为可能重新启动附录的编号会导致 latex/pandoc 混淆并链接到第 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 块中包含附录章节之前完成,而不是从附录章节内部完成。使用附录文件执行此操作意味着附录的第一页/部分没有正确编号,可能是因为 Knitr 创建输出的顺序。
关于latex - 如何在不破坏交叉引用的情况下更改 r-markdown 中附录的章节/部分/页码模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57335284/