16

How do I insert a linebreak in the title of an rmarkdown document? This does not work:

---
title: "title \break subtitle"
output: pdf_document 
---`
Michael
  • 5,808
  • 4
  • 30
  • 39
  • 3
    possible duplicate of [How can I force a line break in rmarkdown's title?](http://stackoverflow.com/questions/28895109/how-can-i-force-a-line-break-in-rmarkdowns-title) – rawr Mar 23 '15 at 00:00

1 Answers1

29

Use pipes

The pipe symbol at the end of a line in YAML signifies that any indented text that follows should be interpreted as a multi-line scalar value. See the YAML spec.

Specifically, the pipe indicates that (except for the indentation) the scalar value should be interpreted literally in such a way that preserves newlines. Conversely, the > character indicates that multi-line "folded" scalar follows, meaning that newlines are converted to spaces.

what is the use of pipe symbol in yaml

---
title: |
    | title 
    | subtitle
output: pdf_document 
---

enter image description here

This is a duplicate but I can't find the original.

edit: here it is!

How can I force a line break in rmarkdown's title?

Community
  • 1
  • 1
rawr
  • 20,481
  • 4
  • 44
  • 78
  • Thanks, this worked. Care to explain why pipe is working/what exactly it's doing? Is the pipe YAML syntax? Why doesn't \\ or \break work? – Michael Mar 19 '15 at 21:12
  • 3
    This appears to work in html and pdf output styles but not "word_document" - any idea why and how to coerce the same in a word document? – enRANDOMSTRING Sep 22 '18 at 04:47
  • 1
    @enRANDOMSTRING [this solution](https://stackoverflow.com/a/41004076/4137985) works for me with word_document – Cath Nov 15 '19 at 14:45