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?
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.
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.
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) ).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With