Page Numbering in R Bookdown

How do you reach the Roman numerals for things like the preface, confirmation, etc., and restart the Arabic numbering at 1 for the first page of the first chapter in R Bookdown.

I want to make a PDF in bookdown, but did not find any good information on how to paginate like this

thanks

+5
source share
2 answers

PDF output is created using LaTeX using the book document class. In this class, you can use \frontmatter , \mainmatter and \backmatter to separate the different "parts" of a book. To use this with bookdown , I did the following:

  • start with a copy of https://github.com/seankross/bookdown-start
  • copy <R-library-path>/rmarkdown/rmd/latex/default-1.17.0.2.tex as book.tex to the working directory
  • update book.tex include \frontmatter , \mainmatter and \backmatter (below)
  • update _output.yml for link to book.tex as template (below)

With these changes, a PDF created using bookdown (loweercase) Roman numerals for ToC and restarted with Arabic numbers for the actual body. Here's 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)$ 
+8
source

I think it would be easier to just follow the @yihui example that was used in his bookdown krantz example :

Add the following files, possibly to the /latex subfolder:

  • preamble.tex with the latex \frontmatter at the end,
  • after_body.tex using the latex \backmatter ,

Then, before your first actual main body, simply add the \mainmatter (only in latex), say, to your index.Rmd (whatever your *.Rmd , usually index.Rmd ).

Then, to modify your _output.yml as follows:

 bookdown::pdf_book: includes: in_header: latex/preamble.tex after_body: latex/after_body.tex 

This alternates the correct \frontmatter , \mainmatter and \backmatter in your Latin pandoc-ed book. This will be followed by most style files to make sure that Arabic numbering starts only inside the main question.

This is also described in the publication of the bookdown chapter of the book.

+2
source

Source: https://habr.com/ru/post/1267335/


All Articles