7

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.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Outlander
  • 533
  • 7
  • 12
  • Show your code where you have used `|` – Urvah Shabbir Jul 28 '18 at 07:37
  • `|` This is working pretty nicely on my system for both pdf and html – Urvah Shabbir Jul 28 '18 at 07:38
  • 1
    @urwaCFC I have updated it . I can get it to work for pdf and html as well but not for word. If i cant convert the document into word in the appropriate format Rmarkdown is useless to me since everyone in chemistry are using word. I am trying to use it because i am using R for all the graphs so it would be great to have everything (R code and text) in one document that i can edit accordingly for each new publication. I am fed up of doing formatting rather than science. – Outlander Jul 28 '18 at 07:49
  • Sorry, I misread the question. You are right pipes do not work for MS Word. – Urvah Shabbir Jul 28 '18 at 08:20
  • After looking it up for a decent while, I believe your question deserves an upvote. – Urvah Shabbir Jul 28 '18 at 08:44

1 Answers1

11

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

jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • 2
    This was one of the things i tried and was careful to include the two spaces. Your solution works also due to the " " that you used to surround the text. Also it has to be " and not ' (seriously R Markdown??). Could you please include this in the answer so i can accept it (i appreciate it might be obvious, just trying to consider the non specialist). Also if you know how to do this multiple times (so leave some blank lines) that would be great. I tried using \n \n \n but just left a larger space only rather than 3 empty lines. Thank you very much for your help!! – Outlander Jul 28 '18 at 12:39
  • 1
    @jay.sf Nice advice on the leading two spaces? – John Mar 15 '19 at 01:37