How to Force a Line Break in Rmarkdown'S Title

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

Try using a pipe | in each line:

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

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

Sample Image

Insert a linebreak in title

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
---

Sample Image

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?

Force line break (br/) in header (h1) in Markdown

Turns out the answer is just "use <br/>."

# Title <br/> byline

produces

<h1>Title <br/> byline</h1>

** facepalm **

R knitr: force linebreak in headline

Actually, you were almost there. You need to put the Latex Code in $...$. Using this code

---
title: "TEST"
author: "Tester"
output:
pdf_document: default
html_document:
df_print: paged
---

# Fancy long headline in R Markdown

\newpage

# Working!

## Fancy long headline in $\\$ <br> R Markdown

gives

Sample Image

and

Sample Image

Split the title onto multiple lines?

For an HTML output just us the <br> tag while if your output is a PDF or PDF presentation standard LaTeX code to break line given by \\ should work.

Example

---
title: 'A title I want to <br> split on two lines'
author:
date:
output:
ioslides_presentation
---

For PDF

Just to rule out possibilities, I've tried to put \\ or \newline, both do not split, so for PDF seems to be a little bit tricky. \linebreak stop knitr parsing. Maybe another user can solve this question for knitr PDFs.

Header line break in Rmarkdown, change textsize after, included as a whole in TOC

I think LaTeX might give you more options for what you'd like here. In LaTeX, you can you "\\" to create a line break almost anywhere in the code. Then, to get the TOC left-aligned like in your example output, you can use the "tocloft" package and set the indentation for subsections with "\cftsetindents{subsection}{0in}{0in}".

---
title: "Untitled"
output: pdf_document
header-includes:
- \usepackage{tocloft}
---
\cftsetindents{subsection}{0in}{0in}

\hypertarget{toc}{}
\thispagestyle{plain}
\tableofcontents

\section{Header}

\subsection[Subtitle \\ \emph{Author's Name}]{Subtitle \\\\ \normalfont{\emph{Author's Name}}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur.

Output:

Sample Image

Edit:

If you want to remove the page number from being added to the "\section" names in the TOC (i.e. "Header" in this case), then there's a two-step solution I know of: (1) you can add an asterisk (*) between "\section" and the name of the section "{Header}" to exclude that section from being listed in the TOC; (2) then you can add the bold-font name of the section into the related subsection portion of the TOC (again using \\ for line breaks) so that the section name appears in the TOC by name only, not number.

Output:

Sample Image

Add line break after caption title in R Markdown

You can use the caption package from LaTeX to control the outputs to PDF. We need to change some of the settings of this file to achieve your changes, but these can be included either as a separate .tex file, or in this case where only a few changes need to be made, we can just insert them within the frontmatter directly. Here is a minimal example:

---
output: pdf_document
header-includes:
- \usepackage{caption}
- \captionsetup{labelfont=bf, labelsep = newline}
---

```{r table1}
caption <- "your long long long caption"
knitr::kable(mtcars, caption = caption)
```

Sample Image

This approach only works for LaTeX outputs (i.e. PDF).

If you want to make more changes to the style, check out the package documentation here: http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/contrib/caption/caption-eng.pdf

Line breaks in R Markdown text (not code blocks)

I tried these tests, it seems to be working:

test.Rmd

---
output: pdf_document
---

# test 1
No spaces used

line1
line2


# test 2
2spaces at the end of line1

line1
line2

# test 3
2spaces at the end of line1, then 2 spaces on next line

line1

line2

Sample Image

sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] htmltools_0.2.6 tools_3.2.0 yaml_2.1.13 rmarkdown_0.5.1 digest_0.6.8


Related Topics



Leave a reply



Submit