Question Details

No question body available.

Tags

css r r-markdown bookdown

Answers (1)

February 25, 2026 Score: 0 Rep: 12,291 Quality: Medium Completeness: 80%

Thanks for this MRE. Moving to an answer because that's easier to share code. I will delete if I'm wrong. It seems like, you have to use the stylesheet argument in bookdown::epubbook + the !important notation to enforce your styles.

renderbookdown.R

# EPUB:

bookdown::renderbook(input="index.Rmd", bookdown::epubbook(figwidth = 5, figheight = 4, dev = "png", figcaption = TRUE, numbersections = TRUE, toc = FALSE, tocdepth = 2, stylesheet = "style.css", metadata = NULL, chapterlevel = 1, mdextensions = NULL, pandocargs = NULL, template = "default" ) )

PDF:

bookdown::renderbook(input="index.Rmd", "bookdown::pdf_book")

styles.css

p.caption {
  color: #777;
  margin-top: 10px;
}
p code {
  white-space: inherit;
}
pre {
  word-break: normal;
  word-wrap: normal;
}
pre code {
  white-space: inherit;
}

.caption { text-align: left; }

/ my styles Id:1923170 I added !imporant here to overwrite any styles added by readers such as https://epub-reader.online/ / h1, h2, h3, h4, p { page-break-after: avoid !important; break-after: avoid !important; page-break-inside: avoid !important; widows: 3; orphans: 3; }

Then my styles are applied; verified using this epub reader + using ReadEra on mobile.

res