HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Double spacing in R Markdown for PDF #96

Open christophergandrud opened 8 years ago

christophergandrud commented 8 years ago

If you would like double spacing in your R Markdown PDF document include \usepackage{setspace}\doublespacing in the header under header-includes.

For example:


---
title: "A Title"
author: "Some authors"
header-includes:
    - \usepackage{setspace}\doublespacing
output: pdf_document
bibliography: main.bib

---
philipp-stdr commented 8 years ago

The code by Cristopher works perfectly for me. However, I get the following warning:

Warning in install.packages : package ‘setspace’ is not available (for R version 3.2.3)

Thus, I cannot create the respective citation because R Studio does not find the package. Did anyone encounter the same problem?

christophergandrud commented 8 years ago

Hi @philipp-stdr setspace isn't an R package, it's a LaTeX package, so you can't use R to create a citation from it.

I know it's kind of inconsistent, but it isn't common place to cite LaTeX packages, so no need to worry about this.

philipp-stdr commented 8 years ago

Okay, thank you for your help!

sixtyfive commented 7 years ago

Is there any way to exclude the first page from getting the double spacing?

christophergandrud commented 7 years ago

Not an easy way that I know of. You could of course create your own LaTeX style file.

ikashnitsky commented 6 years ago

Is there any way to exclude the first page from getting the double spacing?

Is there any update to this question? Also, it would be extremely useful to to have a different spacing param for a part of a document, e.g. the reference list

christophergandrud commented 6 years ago

@ikashnitsky it would probably be better to raise this question with rmarkdown directly. Much higher chance of getting an answer.

yantongli commented 5 years ago

The solution works perfectly fine for me without any warning. I'm using RStudio 1.1.456.

jacobwhall commented 3 years ago

@sixtyfive @ikashnitsky

Is there any way to exclude the first page from getting the double spacing?

RMarkdown accepts LaTeX commands after the header, so I suggest using additional setspace commands throughout your document to control when doublespace is turned on and off. So do your header like

---
header-includes:
  - \usepackage{setspace}
---

...and then when you want to switch to double spacing, toss in a \doublespacing

This might solve your problem if you know where your first page break is. Add a quick \doublespacing at the page break and your document will come out as described. Having LaTeX switch spacing at the page break automatically would require more LaTeX magic than I'm able to conjure up at the moment.