gpt4 book ai didi

r - 在 R Markdown 中使用自定义 LaTeX 类更改编号

转载 作者:行者123 更新时间:2023-12-04 09:41:36 25 4
gpt4 key购买 nike

我最近发现您可以在 R-Markdown 文档中包含自己的 LaTeX 类来更改 PDF 的外观。这是一个最小的例子:

R Markdown

---
title: "Test"
date: "`r format(Sys.time(), '%d %B, %Y')`"
documentclass: book
output:
pdf_document:
citation_package: natbib
toc: yes
toc_depth: 3
number_sections: true
fontsize: 12pt
---

# A
## AA
### AAA
### AAA
## AB
# B

这按预期工作。

enter image description here

但是当我定义自己的类时,编号前面是 0,页编号关闭。

myclass.cls

我将一个名为“myclass.cls”的文件放在与上面的 RMD 文件相同的目录中并更改 documentclass: myclass :
\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{glasgowthesis}

\LoadClass{book}

我的理解是,这应该只是调用与上面相同的类,但文件现在看起来像这样:

enter image description here

也许有人可以给我一个提示,我做错了什么。我想在开始改变之前1:1复制书籍类。

最佳答案

我在 bookdown book 中找到了解决方案并想分享它,以防有人通过谷歌等徘徊在这个问题上。

Note that when you change documentclass, you are likely to specify an additional Pandoc argument --top-level-division=chapter so that Pandoc knows the first-level headers should be treated as chapters instead of sections (this is the default when documentclass is book)



所以这个 YAML header 解决了这个问题:
---
title: "Test"
date: "`r format(Sys.time(), '%d %B, %Y')`"
documentclass: myclass
output:
pdf_document:
pandoc_args: --top-level-division=chapter
citation_package: natbib
toc: yes
toc_depth: 3
number_sections: true
fontsize: 12pt
---

# A
## AA
### AAA
### AAA
## AB
# B

关于r - 在 R Markdown 中使用自定义 LaTeX 类更改编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62308191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com