How to delete blank pages in Rmarkdown(pagedown)
Asked Answered
U

1

8

This is my code:

---
title: "A Multi-page HTML Document"
author: "Yihui Xie and Romain Lesur"
date: "`r Sys.Date()`"
output:
  pagedown::html_paged:
    toc: true
    toc_depth: 3
    # change to true for a self-contained document, but it'll be a litte slower for Pandoc to render
    self_contained: false
---

# Exercises 1 {-}

# Exercises 2 {-}

# Exercises 3 {-}

How do I fix these blank pages? I would like to erase then.

Unbowed answered 13/10, 2019 at 17:14 Comment(2)
I just saw this issue on github for pagedown: github.com/rstudio/pagedown/issues/145Posh
Please, see my answer to the issue mentioned by @Posh github.com/rstudio/pagedown/issues/145#issuecomment-542403855Mcdaniels
T
5

Like people in the comments said, the only way you can solve this is by using your own style. It will be nice if they provide a built-in option to do that in the future.

/* page size */
@page {
  size: 6in 9in;
}

/* store some string variables */
.shorttitle1 {
  string-set: h1-text content(text);
}

.shorttitle2 {
  string-set: h2-text content(text);
}

/* left page */
.running-h1-title {
  position: running(runningH1Title);
  width: var(--running-title-width);
  text-overflow: ellipsis;
  overflow: hidden;
}
.running-h1-title:before {
  content: string(h1-text);
}

@page :first {
  @top-left {
    content: none;
  }
  @top-right {
    content: none;
  }
  @bottom-right {
    content: none !important;
  }
  background-image: var(--front-cover);
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
}

@page :left {
  @top-left {
    content: counter(page);
  }
}

@page :right {
  @top-right {
    content: counter(page);
  }
}

/* Front cover */
.front-cover {
  break-after: page;
}

/* page breaks; aka CSS fragmentation */
.level1 {
  break-before: page;
}
.section > h1, .section > h2, .section > h3, .section > h4, .section > h5, .section > h6 {
  break-after: avoid;
}
.footnotes {
  break-before: always;
  break-after: always;
}
.figure {
  break-inside: avoid;
}

/* do not break captions */
caption {
  break-inside: avoid;
  break-after: avoid;
}

and using it like that:

---
title: "A Multi-page HTML Document"
author: "Yihui Xie and Romain Lesur"
date: "`r Sys.Date()`"
output:
  pagedown::html_paged:
    toc: true
    toc_depth: 3
    # change to true for a self-contained document, but it'll be a litte slower for Pandoc to render
    self_contained: false
    css:
      - custom.css
---

# Exercises 1 {-}

# Exercises 2 {-}

# Exercises 3 {-}
Trinl answered 22/10, 2019 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.