3

When using

render_book("index.Rmd", "bookdown::pdf_book")

it looks like a line setting the margins is inserted in the tex file

\usepackage[margin=1in]{geometry}

The bookdown-demo repro can be used to reproduce this.

In index.Rmd, I'm using

--- 
date: "`r Sys.Date()`"
knit: "bookdown::render_book"
documentclass: krantz
classoption: numberinsequence,krantz1
bibliography: [book.bib]
biblio-style: apalike
link-citations: yes
colorlinks: yes
---

and this is goofing up the margins set by that style file. I know that I can modify the geometry options but can I just avoid this line being generated?

Thanks

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.4

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bookdown_0.4

loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5    rprojroot_1.2   htmltools_0.3.6
[5] tools_3.3.3     rstudioapi_0.6  yaml_2.1.14     Rcpp_0.12.11   
[9] stringi_1.1.5   rmarkdown_1.5   knitr_1.16      stringr_1.2.0  
[13] digest_0.6.12   evaluate_0.10  
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
topepo
  • 13,534
  • 3
  • 39
  • 52

2 Answers2

5

documentclass: krantz indicates that you are writing a book for Chapman & Hall, and I have provided a starter repo bookdown-crc for such authors who use bookdown (the bookdown-demo repo is not the best option for you). Your issue does not exist in this repo because I set template: null for pdf_book in _output.yml. The reason for this is that I wanted to use Pandoc's default template, which does not add the default margin=1in to the geometry option in YAML (and rmarkdown does -- that is the culprit).

If you do want to use rmarkdown's LaTeX template (which is modified based on Pandoc's), you can set

geometry: false

in the YAML metadata of your index.Rmd.

For your reference, I have a section specifically for Chapman & Hall authors in the bookdown book: https://bookdown.org/yihui/bookdown/publishers.html

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
0

The krantz.cls indeed provides the margin settings you need to use for CRC. I was tempted to use my own geometry margin setting, but it messes with the trim cuts, so it's best to let krantz.cls take care of it. You do need to make sure everything fits, including output from code chunks, and tables can be problematic.

For kable tables, this was useful to avoid exceeding the margins:

knitr::kable(head(runoff), caption = '...', format="latex") %>% 
    kable_styling(latex_options="scale_down")

The hard part is getting things working for both html and latex/pdf, and I found this structure useful.

if (knitr::is_latex_output()){
  knitr::include_graphics(here::here("img","myscreenshot.png"))} else {
  `code for creating the output in html`
  }