您如何为前言、致谢等内容实现罗马数字,并在 R Bookdown 第一章的第一页重新开始阿拉伯编号为 1。
我想在 bookdown 中渲染为 pdf,但没有找到任何关于如何更改页码这样的好信息
谢谢
另请查看@maxheld 的答案。它更简单,并且对于许多用例来说已经足够了。另一个不需要编辑模板的简单解决方案是:
---
title: Page Numbering in R Bookdown
documentclass: book
output:
bookdown::pdf_book: default
header-includes:
- \AtBeginDocument{\frontmatter}
---
\mainmatter
# Header 1
Some text
\backmatter
# Appendix 1
Some text
这插入\frontmatter,\mainmatter并\backmatter在正确的位置。
PDF 输出是使用book文档类使用 LaTeX 生成的。在本课程中,您可以使用\frontmatter,\mainmatter和\backmatter来分隔本书的不同“部分”。为了将其与bookdown我一起使用,我执行了以下操作:
<R-library-path>/rmarkdown/rmd/latex/default-1.17.0.2.tex到book.tex工作目录book.tex以包括\frontmatter,\mainmatter和\backmatter(下面的差异)_output.yml以引用book.tex为template(下面的差异)通过这些更改,生成的 PDFbookdown使用 ToC 使用的(小写)罗马数字,并以实际正文的阿拉伯数字重新开始。这里的差异:
diff --git a/_output.yml b/_output.yml
index 112cf5b..b211ba7 100644
--- a/_output.yml
+++ b/_output.yml
@@ -13,5 +13,6 @@ bookdown::pdf_book:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
+ template: book.tex
bookdown::epub_book:
stylesheet: style.css
diff --git a/book.tex b/book.tex
index 0f9979d..3d03540 100644
--- a/book.tex
+++ b/book.tex
@@ -235,6 +235,9 @@ $header-includes$
$endfor$
\begin{document}
+$if(book-class)$
+\frontmatter
+$endif$
$if(title)$
\maketitle
$endif$
@@ -263,8 +266,14 @@ $endif$
$if(lof)$
\listoffigures
$endif$
+$if(book-class)$
+\mainmatter
+$endif$
$body$
+$if(book-class)$
+\backmatter
+$endif$
$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
我认为按照@yihui 在他自己的bookdownkrantz示例中使用的示例可能会更容易:
添加以下文件,可能在/latex子文件夹中:
preamble.tex最后使用 latex\frontmatter命令,after_body.tex使用乳胶\backmatter命令,然后,在您的第一个实际主体之前,只需将\mainmatter命令(仅在乳胶中)添加到您的index.Rmd(通常是您*.Rmd的 s 中的第一个index.Rmd)。
然后,修改你的_output.yml喜欢:
bookdown::pdf_book:
includes:
in_header: latex/preamble.tex
after_body: latex/after_body.tex
这会将正确的\frontmatter,\mainmatter和\backmatter命令散布到您的 pandoc 编辑的乳胶书中。大多数样式文件都会尊重它,以确保阿拉伯编号仅在主要内容内开始。
这也记录在bookdown book的出版章节中。
其实很简单:
在前面的部分这样做:
\cleardoublepage
\pagenumbering{roman}
在主体部分:
\cleardoublepage
\pagenumbering{arabic}