如何在rmarkdown的标题中强制换行?

66

我在 rmarkdown 文档中有一个相当长的标题,我想在特定位置强制换行。

最小示例:

---
title: "Quite long title want the * line break at the asterisk"
output: html_document
---

我尝试过:\n、\newline、\\和手动换行符,但似乎都不起作用。

我相信这应该很简单,但我找不到解决办法。

4个回答

112

尝试在每行中使用竖线符号|

---
title: |
  | Veryyyyyyy  
  | yyyyyyyyyyyyyy Looooo  
  | oooooooooooooooo
  | oooooooooooong 

author: "Foo Bar"
date: "6 March 2015"
output: html_document
---

输入图像说明


31
请注意,管道符前的4个空格和管道符后的单个空格是必要的! - HansHarhoff
3
两个空格加竖线(如上面的代码)也可以使用。 - Chris Holbrook
3
现在对我来说,管道前有两个空格,后面有一个,没有引号,这样就可以了。 - Larry Hunsicker
8
为什么在输出格式为pdf_document和html_document时可以工作,但在word_document中不行?有没有办法在Word文档中实现相同的效果? - enRANDOMSTRING
1
首先,非常感谢!对我来说起作用了,但只在第一行使用了管道符号。对于每个换行符,我在末尾添加了两个空格,但没有使用任何竖线字符。 - george
显示剩余3条评论

22

对于一个居中、多行的标题:

---
title: |
  <center> Veryyyyyyy </center>
  <center> yyyyyyyyyyyyyy Looooo </center>
  <center> oooooooooooooooo </center>
  <center> oooooooooooong </center>

author: "Foo Bar"
date: "6 March 2015"
output: html_document
---

输入图像描述


这对于Beamer RMarkdown标题如何工作?当我尝试时,我会收到一个错误。 - wolfsatthedoor

4

我知道这是一篇旧文章,但我还想发表一下自己的看法:

# A Title of some kind
<br><br><br><br><br>  

# Another title that has 5 blank lines above it

请注意,在第3行需要输入2个空格,否则在Rmarkdown::html_document中标题将无法正确显示。这个解决方案有点难以找到,希望对您有所帮助!

0

我无法对所选答案发表评论。首选解决方案会在标题内创建表格时出现警告。多行标题的正确方法应该是:

---
title: |
    Quite long title want the
    line break at the asterisk

output: html_document
---


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接