6

When declaring output format in YAML section of my Rmarkdown document, is there a way to make sure it knits to PDF, but looks like a knitted HTML?

Nothing about knitted PDF looks the same: the font is some flavor of serif (assume I can change that), blockquotes and code chunks look different.

I like knitted HTML and the look, but is there a way to generate a PDF looking exactly the same?

As an example, just a simple default sample code:

---
title: "Untitled"
output:
  html_document: default
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

> This is a quote

This is a link: <http://rmarkdown.rstudio.com>

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

Here are 2 samples how 2 outputs look out of the box

HTML

PDF

Taraas
  • 1,268
  • 1
  • 11
  • 20
  • 4
    Those are such different outputs. Maybe render to HTML and then just use your browser to print to PDF? The HTML output doesn't really have control over page breaks. If there are just a specific set of things you like to change, it would be better to enumerate them. Just make "PDF look like html" is too broad a topic. A specific [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would be helpful. – MrFlick Nov 15 '17 at 21:09
  • @MrFlick, edited. Knit to HTML and then convert sounds interesting, but I need those page breaks though... – Taraas Nov 15 '17 at 21:47
  • 3
    Wanting & needing are awesome character building traits if followed through sufficiently. There's no magic here, just elbow grease. Dig in and see what you can accomplish! (i.e. nobody is going to magically make this functionality appear for you). – hrbrmstr Nov 16 '17 at 01:32
  • 1
    Sharing your need for this functionality. Were you able to find a workaround to create a html-style knitted .pdf? – JDG Nov 05 '18 at 13:30
  • 1
    @J.R. Yes, I used a custom layout instead (I think the package `tint`) – Taraas Nov 06 '18 at 14:07

0 Answers0