How to indent new paragraphs? - r

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.

Related

RMarkdown Add fold marks to PDF-document

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:

Styling of Ms Word not working in R Markdown

Have tried styling MS Word document from the markdown but I don't seem to get it write. What could I not be doing right? Below is the code
---
title: "Test Document"
author: "Moses Otieno"
date: "05/04/2021"
output:
word_document:
reference_docx: referent-doc.docx
---
```{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>.
## Test
This is the test
Referent Document https://www.dropbox.com/scl/fi/dyww5eiga334j55t58vcp/referent-doc.docx?dl=0&rlkey=o1ejilu3dfnncar65irh5er7v
Resulting document https://www.dropbox.com/scl/fi/mieqkcvy22eeighdjaby3/Test.docx?dl=0&rlkey=8wyrci2cg0ijyxbfdw5ks1znh
In a nutshell, make a template using an already knitted document containing your content and different types of headers etc.
I had a similar problem that was fixed by knitting my document and saving the resulting word(.docx) as "template". I now had a good working file with lots of content examples.
Next, I went into this file and manually changed the styles using "styles" in the Home tab. Open up this feature in your new "template" document by using the little down arrow on the bottom right-hand corner. Click on the various paragraphs and headers in your document to see what they refer to (the style will jump about on the dropdown menu) and make your changes. Save again. Now when you want to knit a new document, it will hopefully apply your changes.
Be aware that you might get caught out by the "Body Text" and "First Paragraph", so you might need to change both of these separately.
output:
word_document:
reference_docx: template.docx
In the YAML part of your project, you have to change your referent.docx into "referent-doc.docx", surrounded by quotation marks (" "):
output:
word_document:
reference_docx: "referent-doc.docx"
# quoted with quotation marks, and here located in the same folder
P.S. Be sure to produce a good reference_doc: You need to start from a .docx file which is produced by markdown (e.g., using the knit button), in order to get a few titles, texts, figs and tables into a .docx. Then edit the styles; margin, etc. from Microsoft Word, and save it to a .docx file.

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:

rmarkdown, columns for text in word documents

using Rmarkdown with R studio.
I am making a word document (html will not do).
I have a text in a rmarkdown, sometime contains code block.
I am trying to create two columns from this text. :
---
output: word_document
---
#Column 1
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>.
#Column2
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:
I have been unable to find any solutions or anything close to a solution. The closes I have come is using \begin{column} and \end{column}, but it was an old tutorial and did not work for me... or I was doing it wrong.
Try the following in your YAML header -
classoption: twocolumn

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)
```

Resources