Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First-line paragraph indenting in PDFs using R Markdown

I'm hoping this is a question with a simple answer. I am using Rmarkdown/knitr to author a PDF document (in RStudio). Many LaTeX classes (like article) automatically indent the first line of a paragraph of text, but Rmarkdown does not, nor can I figure out a way to do so.

Here's a simple example:

---
title: "minimal"
author: "prison rodeo"
output: pdf_document  
---

This is an R Markdown document. 

I would like this paragraph to be first-line indented, but it is not.

Using > indents the entire paragraph, which is not what I'm looking for. I've tried spaces/tabs at the beginning of each paragraph, and using \indent; neither seems to work. Any ideas?

like image 367
Prison Rodeo Avatar asked Apr 05 '15 17:04

Prison Rodeo


People also ask

How do you indent a paragraph in Rmarkdown?

Text can be indented two ways depending on if the indent is within a list or not. Within a list, four spaces at the begin of the line indicates the text is to be indented one nesting level. Use four additional spaces for each additional nesting level. To indent text which is not in a list, use a block quote.

How do you Markdown a PDF in R?

Rendering. 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 you indent in R studio?

Magic shortcut: Command+I ( Ctrl+I for Windows/Linux) will indent a selected chunk of code.

How do you indent the first line of a para?

To indent the first line of a paragraph, put your cursor at the beginning of the paragraph and press the tab key. When you press Enter to start the next paragraph, its first line will be indented.


2 Answers

The default Pandoc template includes an indent argument. If set to true, paragraphs start with an indentation.

----
title: "Title"
author: "Me"
output: pdf_document
indent: true
----
like image 117
Stefano Avatar answered Sep 20 '22 19:09

Stefano


I believe the following in your YAML header will work the same and has the advantage of still compiling should you decide to knit your document to an HTML file (though, I haven't tested this).

----
title: "Title"
author: "Me"
header-includes:
   - \setlength\parindent{24pt}
output:
    pdf_document
----
like image 32
Benjamin Avatar answered Sep 17 '22 19:09

Benjamin