Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split title in two lines in Rmarkdown for word output

I have seen various solutions around which work for pdf and HTML document output. However, none worked for me for word output. When used | as suggested here: Split the title onto multiple lines? simply made the whole title disappear. Here is the code:

---  
title: |
    | Supporting Information
    | Development and mechanistic bla bla.
author: Some people
output:
  word_document:
    reference_docx: ACS SI style for RMD.docx
mainfont: Arial
---
<style>
body {
text-align: justify}
 p {line-height: 1.5em;}
</style>

Any help would be much appreciated.

like image 413
Outlander Avatar asked Jul 27 '18 13:07

Outlander


People also ask

How do you insert a line break in R Markdown?

To break a line in R Markdown and have it appear in your output, use two trailing spaces and then hit return .

How do you bold a title in R Markdown?

To write text in bold font, use a double asterix or underscores before and after the text.

How do you comment multiple lines in R Markdown?

After drag the lines you want to make comment, press SHIFT + CMD + C (macOS), SHIFT + CTRL + C (Windows). This is the shortcut of R Markdown editor (R Studio) to comment out.


1 Answers

The | pipes do not work together with word. Set the title into "" instead. For a line wrap in the title with output to word we can use:

  \n

(important: headed by two spaces!).

---  
title: "Supporting Information  \nDevelopment and mechanistic bla bla."
author: Some people
output: word_document
---

Yielding

enter image description here

Empty lines

To achieve empty lines within the title word wants "something" in these lines, so we can set a non-breaking space after the line breaking code:

  \n &nbsp;

(important again: \n headed by two spaces!).

---  
title: "Supporting Information  \n &nbsp;  \n Development and mechanistic bla bla."
author: Some people
output: word_document
---

Yielding

enter image description here

like image 79
jay.sf Avatar answered Oct 17 '22 16:10

jay.sf