latex - 如何在不破坏交叉引用的情况下更改 r-markdown 中附录的章节/部分/页码模式?

标签 latex rstudio r-markdown pandoc bookdown

我正在使用 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/

相关文章:

latex list : Define Font

在安装了 64 位 R 的 64 位操作系统上运行 32 位 RStudio

r - 如何改变rmarkdown中目录的位置?

r - 在 RMarkdown 文档中添加 ggvis 绘图会使 knit::kable 输出渲染不正确

perl - 由于缺少 perl 模块,在 Windows 10 上使用 LaTeX Workshop 在 VSCode 上格式化文档时出错

graphics - 在 LaTeX 中,有没有办法将图形的文件名包含到标题中?

android - 在 Android 上安装 R

r - 使用 knitr::include_graphics() 在 RStudio 笔记本中包含图像

r - 在rstudio/knitr文档中导入常见的YAML

latex - latex 字母: From Address Left aligned