1

I wanted to create a horizontal rule that stretches the full width of a pdf, and also works in my HTML files that are knitted from R Markdown. I followed outlined here, shown below, which worked very well.

A problem with the solution is that it creates a giant block of 'white space' between the heading and horizontal rule. How do I eliminate, or reduce the size, of this 'white space'?

Here is the method I used. Firstly, a tex file is made called header.tex, containing:

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

Then in the Rmd file put:

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

And this is the result:

space.png

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
stackinator
  • 5,429
  • 8
  • 43
  • 84

1 Answers1

2

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

enter image description here

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

enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84