I would like to force a linebreak in a long headline in an R markdown file knitted with knitr to both PDF and HTML output. At best, referencing of the headline should still work.
The following solutions proposed for related issues did not solve the issue: \\
, \n
, <br>
, <br>
(the latter two work for HTML only).
---
title: "TEST"
author: "Tester"
output:
pdf_document: default
html_document:
df_print: paged
---
# Fancy long headline in R Markdown
\newpage
# Not working:
## Fancy long headline in \\ R Markdown
# Work in HTML only:
## Fancy long headline in <br> R Markdown
## Fancy long headline in <br /> R Markdown
<!-- ## Fancy long headline in \n R Markdown -->
<!-- => ` \n` throws error in LaTex -->
\newpage
# Reference the headline
Reference the [fancy long headline in r markdown]
or similarly in bookdown [fancy-long-headline-in-r-markdown]
or via [myref](fancy-long-headline-in-r-markdown).
Any help is greatly appreciated.
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
and