Search code examples
rlatexr-markdown

RMarkdown: set image as title page (pdf-output)


as it is pretty complicated to replicate a given title page layout in LaTeX, I exported the title page of a MS word file as an image file called titlepage.jpg.

Now, I would like to display that image file on the first page of my pdf document (table of contents should start on the next page). I am facing two difficulties:

  • How can I set the titlepage-image as the first page in the pdf?
  • How can I remove the headings and page numbers from that page?
---
title: "Title of my report"
author:
- Steve Example
date: "`r format(Sys.Date(), '%d.%m.%Y') `"
output:
  pdf_document:
    toc: yes
    toc_depth: 3
    number_sections: yes
toc-title: Content
fontsize: 10pt
lang: de
documentclass: scrreprt
classoption: oneside
header-includes: 
  - \usepackage{helvet} 
  - \usepackage{fancyhdr} 
  - \usepackage[font={small}]{caption}
  - \usepackage[a4paper, total={6in, 9in}]{geometry}
  - \renewcommand\familydefault{\sfdefault}
  - \AtBeginDocument{\let\maketitle\relax}
include-before: '`\newpage{}`{=latex}'
---

\pagestyle{fancy}
\fancyhead{} 
\fancyhead[R]{}
\fancyhead[L]{My University\\ \textbf{IDR} Institute for difficult LaTeX-Reports}
\fancyfoot[C]{\thepage} 

\let\oldsection\section

\thispagestyle{empty}

![](titlepage.jpg)

\\newpage

# First section

## Sub-section
## Another sub-section

# Second chapter

## Sub-section
## Another sub-section

Solution

  • jpg is not a good format for things which contain text, like a title page. I suggest that you instead export your title page as pdf, then you can use the pdfpages package to include the whole page:

    ---
    title: "Title of my report"
    author:
    - Steve Example
    date: "`r format(Sys.Date(), '%d.%m.%Y') `"
    output:
      pdf_document:
        toc: yes
        toc_depth: 3
        number_sections: yes
    toc-title: Content
    fontsize: 10pt
    lang: de
    documentclass: scrreprt
    classoption: oneside
    header-includes: 
      - \usepackage{helvet} 
      - \usepackage{fancyhdr} 
      - \usepackage[font={small}]{caption}
      - \usepackage[a4paper, total={6in, 9in}]{geometry}
      - \renewcommand\familydefault{\sfdefault}
      - \usepackage{pdfpages}
      - \AtBeginDocument{\let\maketitle\relax\includepdf{example-image-a4-numbered}}
    include-before: '`\newpage{}`{=latex}'
    ---
    
    
    
    \pagestyle{fancy}
    \fancyhead{} 
    \fancyhead[R]{}
    \fancyhead[L]{My University\\ \textbf{IDR} Institute for difficult LaTeX-Reports}
    \fancyfoot[C]{\thepage} 
    
    \let\oldsection\section
    
    \newpage
    
    # First section
    
    ## Sub-section
    ## Another sub-section
    
    # Second chapter
    
    ## Sub-section
    ## Another sub-section