Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am aware that *** is Pandoc's Markdown for a horizontal rule. This horizontal line looks good on HTML, but if I knit my Markdown into a pdf the horizontal rule only runs half the width of the pdf, and it is centered. This combination just makes the horizontal rule look plain ugly.

How do I properly put a horizontal rule in my R Markdown that can render properly to both HTML and pdf? Properly == full length/full width. And while I'm at it, can I format the horizontal rule (color, thickness, etc.) without getting into much CSS which I know nothing about.

like image 533
stackinator Avatar asked Mar 30 '18 14:03

stackinator


People also ask

How do you Markdown a PDF in R?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

How do I add a horizontal line in R Markdown?

You can create a horizontal rule ( <hr /> ) by placing 3 or more hyphens, asterisks, or underscores on a single line by themselves.

Can I use LaTeX code in R Markdown?

By default, Pandoc will preserve raw LaTeX code in Markdown documents when converting the document to LaTeX, so you can use LaTeX commands or environments in Markdown.


1 Answers

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
---
like image 109
Stéphane Laurent Avatar answered Oct 19 '22 18:10

Stéphane Laurent