RMarkdown Add fold marks to PDF-document - r

I want to use RMarkdown to create a PDF document with folding marks on the left side.
I have already found a working example for LaTex:
https://tex.stackexchange.com/questions/332368/scrlttr2-wider-folding-marks
Unfortunately, I have not yet found a way to implement this example in my RMarkdown file.
In my opinion this example suggests to change the documentclass-option to scrlttr2.
However, after much research, I have not found a comparable example for RMarkdown.
Can someone help me?
(I would also be happy if you could find another way and create fold marks in RMarkdown.)
Here is my example-code:
---
title: "Untitled"
output: pdf_document
date: "2023-01-17"
header-includes:
\usepackage{fancyhdr}
\usepackage{xcolor}
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

You could use the same approach as in https://tex.stackexchange.com/a/95230/36296
---
title: "Untitled"
output: pdf_document
date: "2023-01-17"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{xcolor}
- \usepackage{tikz}
- \usetikzlibrary{calc}
- \AddToHook{shipout/background}{\begin{tikzpicture}[overlay,remember picture]\draw ($(current page.north west)!0.3535!(current page.south west)$)--++(0.5cm,0cm);\draw ($(current page.north west)!0.50!(current page.south west)$)--++(0.8cm,0cm);\draw ($(current page.north west)!0.7071!(current page.south west)$)--++(0.5cm,0cm);\end{tikzpicture}}
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Related

Include logo (image) on every page of R markdown pdf

I am trying to include my company logo in an R markdown report. The output has to be pdf. The logo has to be used as a template on every page of the report in the top left of the file. Just for example, you can use this google logo https://en.wikipedia.org/wiki/Google#/media/File:Google_2015_logo.svg
I want the report to look like this (sorry for the blurry image but I just wanted to give an example) -
The google logo on top left should be present on every page.
I have done searches but all the searches that I have done are showing how to do this using latex or HTML output.
https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html
Insert a logo in upper right corner of R markdown pdf document
2 Logo in R Markdown on PDF
add image in title page of rmarkdown pdf
The closest I have came is with this markdown document that is called reports.Rmd which looks like -
---
title: "Report"
output: pdf_document
params:
study: NA
mid : NA
---
![Caption.](google.png)
```{r, echo=FALSE}
paste0("Study : ", params$study)
paste0("ID", params$mid)
```
and I run this from another R script as -
library(rmarkdown)
study <- 'ABC'
mid <- '73023'
rmarkdown::render('reports.Rmd', pdf_document(), params = list(
study = study, mid = mid
))
This runs and produce this output
I'll be able to resize the image with How to set size for local image using knitr for markdown? but I don't know how to place this on top left of the page. Thank you for reading.
This is a template for you:
---
title: 'You are really need to use LaTeX'
author: "You"
date: "`r Sys.Date()`"
output:
pdf_document
header-includes:
\usepackage{fancyhdr}
\usepackage{graphicx}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\addtolength{\headheight}{3.0cm}
\fancypagestyle{plain}{}
\pagestyle{fancy}
\fancyhead[R]{\includegraphics[width = 100pt]{your_pic.png}}
\renewcommand{\headrulewidth}{0pt}
This is an R Markdown document. Markdown is a simple formatting syntax for
authoring HTML, PDF, and MS Word documents. For more details on using R Markdown
see <http://rmarkdown.rstudio.com>.
and blah-blah...
So, don't forget to install LaTeX and packages fancyhdr, graphics.
How to do it, you can see there.
Or you can install MikTeX etc. You can find a lot of info at the SO/in the web.
The knowledge of LaTeX will save you not once a time in the future life ;)

Calibri font for a particular set of line in Rmarkdown

Here's a reproducible example of PDF Rmarkdown:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
I need "This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com."
to be in Calibri font than the default one.
If you are okay with setting the latex engine to xelatex, you can use \fontspec{Calibri} to set the font to Calibri and then \normalfont to return to the default font.
---
title: "Untitled"
output:
pdf_document:
latex_engine: xelatex
---
## R Markdown
\fontspec{Calibri}
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
\normalfont
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

How to indent new paragraphs?

How can I change the rmarkdown settings in a way that a new paragraph starts with an indented first line (as the default in LateX) rather than with blank space and no indentation.
That is what I normally get:
---
output: pdf_document
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:**
That is what I want:
In the header of your Rmd document, you can add LaTeX includes. To indent the paragraph, just change parindent, e.g.
output: pdf_document
header-includes:
- \setlength{\parindent}{4em}
- \setlength{\parskip}{0em}
Alternatively, you could store the latex commands in a separate file:
includes:
in_header: header.tex
See the advanced customization section.

Can't pass arguments to pandoc through rmarkdown

I am trying to pass pandoc arguments through rmarkdown YAML as it is linked here: http://rmarkdown.rstudio.com/html_document_format.html#advanced-customization
and the option I am trying to add is code line numbering:
--indented-code-classes=CLASSES
Specify classes to use for indented code blocks–for example, perl,numberLines or haskell. Multiple classes may be separated by spaces or commas.
My .Rmd file is below but after the rendering the output do no look like to be numbered. Does anyone know how to pass this argument correctly? I've tried many various possibilities but none of them worked.
---
title: "Untitled"
author: "Marcin Kosinski"
date: "28.12.2015"
output:
html_document:
theme: united
highlight: espresso
md_extensions: +fenced_code_attributes+fenced_code_blocks
pandoc_args: [
"--indented-code-classes","numberLines"
]
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r, results='hide'}
summary(cars)
iris
summary(iris)
```

How to create customized chapter heading in a Dynamic Document R and knitr

I´m not a LaTex user...actually started learning something about it as consequence of dynamic document I´m working with for a book document class I´m writing in R and knitr.
I´ve tried to customize the chapter headings, but meanwhile I did not get....I found the way to do this by LaTex (https://tex.stackexchange.com/questions/73421/how-to-create-specific-chapter-style-in-book-documentclass) however I´m not knowing how to address by RMardkown.
Does anybody could help me with that? How can I arrange the below LaTex commands to be triggered by RMarkdown (by .sty file?) or something similar way to customize the chapter heading in output pdf?
\documentclass{book}
\usepackage{titlesec}
\usepackage{lipsum} % just to generate text for the example
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{1ex}
{\titlerule\vspace{1ex}\filleft}
[\vspace{1ex}\titlerule]
Thanks
Fabio
You can put the stuff you want in the header, except the documentclass line, in a seperate tex file (I use header.tex below). You can then specify in the header of your R-markdown file that you want to include this file in the header. The documentclass van also be set in the header of your R-markdown file. More info on this can be found on the rstudio site.
Below an example:
---
title: "Untitled"
output:
pdf_document:
includes:
in_header: header.tex
documentclass: book
---
\chapter{Introduction}
Section
=======
This is an R Markdown document.
header.tex looks like:
\usepackage{titlesec}
\usepackage{lipsum} % just to generate text for the example
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{1ex}
{\titlerule\vspace{1ex}\filleft}
[\vspace{1ex}\titlerule]

Resources