Coverpage and copyright notice before title in R bookdown?
Asked Answered
F

1

6

Back in March, I asked a question and got an answer to including coverpage in a pdf document rendered by R bookdown:

R bookdown - cover page and appendix

I tried the solution and came up with the following results:

using in index.rmd yaml:

output:
  pdf_document:
    includes:
      before_body: frontpage.tex
    number_sections: yes
    toc: yes
    toc_depth: 3
site: bookdown::bookdown_site
documentclass: book
classoption: letterpaper

The title still appeared before the coverpage AND the Chapter 'wording' in chapter titles (ie 'Chapter 1' before the actual words for chapter title) disappeared. And the section numbering in each chapter began with 0 etc.

If i take out the includes clause in the above- title and author come up as first page, followed by table of contents and all chapter headings and section numbering come out properly- but then of course no coverpage or copyright page.

frontpage.tex was like the following:

\frontmatter

\includegraphics {coverpage.png}

This edition first published August 2017 etc

How do I get coverpage ahead of title, copyrightpage after title and before table of contents, and have the chapter headings ie (the word chapter and number ahead of chapter title render in that order and properly.

R bookdown has done an amazing job in book layout and formatting so far but I can't seem to make these typical things which would be needed to work.

Thanks...

Fanestil answered 30/8, 2017 at 14:47 Comment(0)
F
5

To get a cover page before the title page in a pdf file generated by bookdown, the trick is to turn off LaTeX's \maketitle command, create the cover page, then turn \maketitle back on and execute it if you want the title page as well.

Starting with the standard bookdown demo, append the following two lines to the end of preamble.tex

\let\oldmaketitle\maketitle
\AtBeginDocument{\let\maketitle\relax}

This saves the \maketitle command as \oldmaketitle and then turns off the original \maketitle. In the same directory, now create a before_body.tex file that contains the following lines

\thispagestyle{empty}
\begin{center}
{\Huge A BOOK}
\includegraphics{cover.png}
{\huge by Me}
\end{center}

\let\maketitle\oldmaketitle
\maketitle

This inserts a page at the beginning of your output pdf, then returns \maketitle to its original state and then executes it. If you already have a before_body.tex file, just add the lines to the end. In the above example, I've included some text before and after the image, just to show that one can.

Finally you need to place your cover image file (cover.png) in the same directory. and build your pdf_book. This will produce a cover page with a title ("A BOOK") followed by the cover picture and then the author ("by Me").

In this example I've used a png file, but pdf or jpg files also work fine. If you have a more complicated directory structure, as in the standard bookdown example, you may have to modify the path to the necessary files, e.g. "latex/preamble.tex" instead of "preamble.tex".

Featureless answered 21/1, 2018 at 19:51 Comment(6)
Does the before_header.tex file get included in the index.rmd yaml as per the original question? Would I get an informative error to let me know I needed to relocate the preamble.tex to another folder and reference it there?Discompose
If you meant "before_body", not "before_header", then yes, before_body.tex needs to be included as in the original question. I follow the example in the bookdown book and put it in a separate latex folder, which may help if you are getting an informative error.Featureless
Yes, I did mean before_header! I have made a repo here and carefully followed the steps suggested, but I get an error message: 'Undefined control sequence. l.127 \maketitle'. I think it might be due to how the before_header is included in the index.rmd as per the original post, when it feels like maybe it should be included in the _output.yml?Discompose
Ok, that repo now works, following the method of including before_header.tex via _output.yml described hereDiscompose
To be clear, to include your before_header.tex file, you need to edit the _output.yml so that the bbokdown::pdf_book: section looks like this (correct indents are important): bookdown::pdf_book: includes: in_header: preamble.tex before_body: before_body.tex latex_engine: xelatex citation_package: natbib keep_tex: yesDiscompose
This approach inserts a blank page before the cover page. How do we remove that?Amaleta

© 2022 - 2024 — McMap. All rights reserved.