16
votes

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?

3
Try adding \setlength\parindent{24pt} at the start (before This is an...) from tex.stackexchange.com/questions/45501/how-to-add-indentationuser20650
That did it! Thanks. If there's a more Rmd-"correct" way to do this, I'd be happy to hear about it as well.Prison Rodeo
Im sure there will be, and hopefully someone will show how. That said i tend to hack these things together like thisuser20650
Adding       at the beginning of a paragraph will indent that first line by 5 spaces. If you're always going to target PDF, the latex solutions are far better.hrbrmstr
@hrbrmstr couldn't you solve this with CSS instead of hardcoding a lot of spaces? For instance, the text-indent property specifies the indentation of the first line in a text-block.Peter H.

3 Answers

23
votes

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
----
5
votes

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
----
1
votes

If what you're after happens to be the default settings in other regards as well, you might also be interested in setting the \parskip option to its default setting, since it is otherwise set to {6pt plus 2pt minus 1pt}

header-includes:
   - \setlength\parindent{24pt}\setlength{\parskip}{0.0pt plus 1.0pt}