Search code examples
rpdflatextitlequarto

Including the title page and back page in a quarto book in PDF format


I'm interested in including the title page (have a title page as a .png image) and back page (have a back page as a .png image) in a quarto book that will be rendered as a PDF file. I tried the following code, however, I did not get the desired output. I would like to know the steps or methods to accomplish this.

---
book:
  title: "Title"
  author: "MYaseen208"
format:
  pdf:
    documentclass: scrreprt
    toc: true
    toc-depth: 3
    include-in-header:
      - text: |
          \usepackage{lipsum}
          \usepackage{geometry}
          \geometry{a4paper, total={170mm,257mm}, left=20mm, top=20mm, bottom=20mm, right=50mm}
---

# Introduction

\lipsum[1-50] 

# Material and Methods

\lipsum[1-20] 

Edited

For example, if I want to include the following image as title and back page of the book.

enter image description here


Solution

  • You could add your images via the \AtBeginDocument and \AtEndDocument hooks:

    ---
    book:
      title: "Title"
      author: "MYaseen208"
    format:
      pdf:
        documentclass: scrreprt
        toc: true
        toc-depth: 3
        include-in-header:
          - text: |
              \usepackage{lipsum}
              \usepackage{tikz}
              \AtBeginDocument{\thispagestyle{empty}\begin{tikzpicture}[remember picture,overlay]
              \node at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{example-image-duck}};
              \end{tikzpicture}\clearpage}
              \AtEndDocument{\clearpage\thispagestyle{empty}\begin{tikzpicture}[remember picture,overlay]
              \node at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{example-image-duck}};
              \end{tikzpicture}}
    ---
    
    # Introduction
    
    \lipsum[1-50] 
    
    # Material and Methods
    
    \lipsum[1-20] 
    

    Some other comments:

    • you shouldn't use the geometry package with a koma class. Koma classes have their own mechanism to change the page layout

    • If you really must use the geometry package, at least don't ignore the warnings and don't overspecify your geometry.

    • png might not be the best option for such a graphic. It does not zoom well and will get pixelated and for such a simple image it will unnecessarily blow up the file size. It would be better to include as a vector graphic.

    • If you'd had your image as a full page pdf, you could use the pdfpages package to include it.