From 3e4eee066d36afc314cb47b0388d2d56b05acaa6 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 8 Aug 2017 22:13:20 -0500 Subject: [PATCH] final fix for #65: dynamically set the page size for printing --- R/render.R | 1 + inst/rmarkdown/templates/xaringan/resources/example.css | 1 + inst/rmarkdown/templates/xaringan_zh-CN/skeleton/zh-CN.css | 1 + 3 files changed, 3 insertions(+) diff --git a/R/render.R b/R/render.R index a6e32cd..4834ef7 100644 --- a/R/render.R +++ b/R/render.R @@ -87,6 +87,7 @@ moon_reader = function( tags$script(HTML(paste(c(sprintf( 'var slideshow = remark.create(%s);', if (length(nature)) knitr:::tojson(nature) else '' ), "if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {window.dispatchEvent(new Event('resize'));});", + '(function() {var d = document, s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler"); if (!r) return; s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }"; d.head.appendChild(s);})();', play_js, countdown_js), collapse = '\n'))) )), tmp_js) diff --git a/inst/rmarkdown/templates/xaringan/resources/example.css b/inst/rmarkdown/templates/xaringan/resources/example.css index a1594ab..48c539b 100644 --- a/inst/rmarkdown/templates/xaringan/resources/example.css +++ b/inst/rmarkdown/templates/xaringan/resources/example.css @@ -71,6 +71,7 @@ table thead th { border-bottom: 1px solid #ddd; } th, td { padding: 5px; } thead, tfoot, tr:nth-child(even) { background: #eee } +@page { margin: 0; } @media print { .remark-slide-scaler { width: 100% !important; diff --git a/inst/rmarkdown/templates/xaringan_zh-CN/skeleton/zh-CN.css b/inst/rmarkdown/templates/xaringan_zh-CN/skeleton/zh-CN.css index fa07b82..2affbf0 100644 --- a/inst/rmarkdown/templates/xaringan_zh-CN/skeleton/zh-CN.css +++ b/inst/rmarkdown/templates/xaringan_zh-CN/skeleton/zh-CN.css @@ -89,6 +89,7 @@ table thead th { border-bottom: 1px solid #ddd; } th, td { padding: 5px; } thead, tfoot, tr:nth-child(even) { background: #eee } +@page { margin: 0; } @media print { .remark-slide-scaler { width: 100% !important;