I am generating a gitbook report with Rstudio the bookdown package.
It is fairly simple in terms of underlying R code, just a few recent tweaks for:
- reducing text to 80% of page width
- using double columns and
- adding line number in the R code displayed.
Everything works well, except when I added "split_by: rmd
" in the _output.yml. When doing so the resulting output doesn't respect the margin around the text anymore.
I don't know much about html yet, but looking at the html inspector revealed that the sections are located outside the inner-page formatting when using "split_by: rmd
"
Default (no split_by argument):
This is a shot in the dark as I cannot share the code and I am not able to reproduce the error with the minimal bookdown example from Yihui: https://github.com/rstudio/bookdown-demo.
Any leads to identify the origin of the error or even better propose a solution would be very welcomed!
Building the book from a R script:
bookdown::render_book(
input = "index.Rmd",
output_format = "bookdown::gitbook",
output_dir = paste0("gitbook-", format(Sys.time(), format = "%Y-%m-%d-%H%M%S"))
)
index.rmd YAML header:
---
title: "blahblah"
subtitle: "blahblahblah"
author: "DRAFT"
date: "August 2020"
documentclass: article
fontsize: 12pt
geometry: margin=2cm
link-citations: yes
#mainfont: Arial
bibliography: packages.bib
site: bookdown::bookdown_site
biblio-style: apalike
urlcolor: blue
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = FALSE, attr.source='.numberLines')
table_format <- knitr::opts_knit$get('rmarkdown.pandoc.to')
if (table_format %in% c("html", "latex")) {
library(kableExtra)
knitr::opts_chunk$set(fig.pos='H', fig.align='center', out.width='80%')
}
## Automatically create a bib database for R packages
knitr::write_bib(c(.packages(), 'bookdown', 'knitr', 'rmarkdown', 'Hmisc'), 'packages.bib')
```
_output.yml:
bookdown::gitbook:
css: style.css
config:
toc:
before: |
<li><a href="./">My book title</a></li>
#after: |
# <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
edit: null
download: null
sharing: null
info: null
split_bib: FALSE
split_by: rmd
style.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;
}
/* watermark for draft report
.watermark {
opacity: 0.2;
position: fixed;
top: 45%;
left: 45%;
font-size: 500%;
color: #606099;
z-index: 1000000;
}
*/
.book .book-body .page-wrapper .page-inner {
max-width: 80% !important;
}
/* Increase space to display line number in R chunks correctly */
pre.numberSource code > span > a:first-child::before {
left: -0.3em;
}
/* for multi cols */
/*.cols {display: flex; } /* uncomment for flex column size */
.cols {display: grid; grid-template-columns: 30% 50% 20%;} /* for fixed column size */