Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting title page with image in Rmarkdown to render a pdf document

In Rmarkdown, the following sets the context to generate the pdf document:

---
title: "My Report"
author: NDE
output:
  pdf_document:
  fig_caption: true
  toc: true
  highlight: kate
---

I want to insert a title page with an image, title before table of contents gets printed. Is there a way I can achieve it?

like image 804
Next Door Engineer Avatar asked Mar 10 '15 11:03

Next Door Engineer


People also ask

How do I make a PDF in Rmarkdown?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

How do I add a title in Rmarkdown?

We'll do this in a R Markdown file in R Studio since it's easy to render to html from there. Firstly, open up a R Markdown file in R Studio. Click the File tab, New File , then R Markdown . Leave the default output as is (HTML), choose a title for the new R Markdown file or leave it blank.

Can you add image to Rmarkdown?

We include external images in our R markdown documents using the include_graphics function from the knitr package. Images can also be included using either raw HTML with img tags ( <img src = "" /> ) or using markdown directly ( ![ image](imagepath) ).

How do I add a header in R markdown?

We can insert headings and subheadings in R Markdown using the pound sign # . There are six heading/subheading sizes in R Markdown. The number of pound signs before your line of text determines the heading size, 1 being the largest heading and 6 being the smallest.


1 Answers

For me it worked using LaTeX commands \clearpage and \tableofcontents:

---
title: "image before toc"
output: pdf_document
---

\centering

![Caption](folder/image.png)

\raggedright
\clearpage
\tableofcontents

# header 1
lore ipsum

## header 2
lore ipsum 

## header 3
lore ipsum 

# header 4

If you want the table of contents on the title page, just leave \clearpage command out.

I included \centering and \raggedright commands to center the image on the title page but not the text.

Hope that works for you.

like image 64
jmjr Avatar answered Oct 18 '22 12:10

jmjr