Horizontal Rule in R Markdown/Bookdown Causing Errors

R Markdown horizontal rule that will also work with LaTeX pdf?

Make a tex file, say header.tex, containing:

\let\oldrule=\rule
\renewcommand{\rule}[1]{\oldrule{\linewidth}}

Then in your Rmd file:

---
title: "test"
author: "Stéphane Laurent"
date: "30 mars 2018"
output:
pdf_document:
includes:
in_header: header.tex
---

pandoc related error on saving rmarkdown file

Hard to tell without seeing the input document. Error 64 is a PandocParseError, and the most likely explanation is a problem in a YAML metadata block.

R Markdown reduce space between heading and horizontal rule

Remove Padding

If you want to remove the padding around the line, you can set a negative vspace command within the line definition as shown here:

\let\oldrule=\rule
\renewcommand{\rule}[1]{\vspace{-25pt}\oldrule{\linewidth}}

And the .Rmd file:

---
output:
pdf_document:
includes:
in_header: header.tex
---

# Title

Test

Test

Sample Image

Underline Header

You are probably better off changing the styles of the header to include the underline as part of the # Title command. This answer shows how it can be achieved in LaTeX

Firstly, the header.tex file becomes:

\usepackage{titlesec}

\let\oldrule=\rule
\renewcommand{\rule}[1]{\oldrule{\linewidth}}

\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{}[{\titlerule[0.8pt]}]

And a basic example. Note that subparagraph: yes is included, and without it the titlesec package cannot be used. See here for the explanation.

---
output:
pdf_document:
includes:
in_header: header.tex
subparagraph: yes
---

# Title

Test

Test

Sample Image



Related Topics



Leave a reply



Submit