Reputation: 627
How do you achieve roman numerals for things like preface, acknowledgement etc and restart Arabic numbering at 1 for first page of chapter one in R Bookdown.
I am wanting to render to pdf in bookdown, but have not found any good information on how to change page numbering like this
thanks
Upvotes: 13
Views: 3560
Reputation: 26823
Please also look at the answer by @maxheld. It is simpler and for many use cases sufficient. Another simple solution that does not require editing the template would be:
---
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
This inserts \frontmatter
, \mainmatter
and \backmatter
in the right places.
PDF output is produced with LaTeX using the book
document class. In this class, you can use \frontmatter
, \mainmatter
and \backmatter
to separate different 'parts' of the book. In order to use this with bookdown
I did the following:
<R-library-path>/rmarkdown/rmd/latex/default-1.17.0.2.tex
as book.tex
to the working directorybook.tex
to include \frontmatter
, \mainmatter
and \backmatter
(diff below)_output.yml
to refer to book.tex
as template
(diff below)With these changes the PDF produced with bookdown
used (loweercase) roman numerals for the ToC and restarted with arabic numbers for the actual body. Here the diff:
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)$
Upvotes: 15
Reputation: 49
It's actually very simple:
In the front matter part do this:
\cleardoublepage
\pagenumbering{roman}
In the main matter part:
\cleardoublepage
\pagenumbering{arabic}
Upvotes: 2
Reputation: 4273
I think it might be easier to just follow the example @yihui used in his own bookdown krantz
example:
Add the following files, perhaps in a /latex
subfolder:
preamble.tex
with the latex \frontmatter
command at the end,after_body.tex
with the latex \backmatter
command,Then, before your first actual main body, just add the \mainmatter
command (just in latex) to, say, your index.Rmd
(whichever of your *.Rmd
s is first, conventionally index.Rmd
).
Then, to amend your _output.yml
like so:
bookdown::pdf_book:
includes:
in_header: latex/preamble.tex
after_body: latex/after_body.tex
This intersperses the correct \frontmatter
, \mainmatter
and \backmatter
commands into your pandoc-ed latex book. It will be respected by most style files to make sure that arabic numbering only begins inside the main matter.
This is also documented in the publishing chapter of the bookdown book.
Upvotes: 10