Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coverpage and copyright notice before title in R bookdown?

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...

like image 487
Lyndon Sundmark Avatar asked Aug 30 '17 14:08

Lyndon Sundmark


1 Answers

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".

like image 131
David Bailey Avatar answered Sep 19 '22 00:09

David Bailey