3

我想将本地目录中的图像/材料包含到 Xaringan remark.js 演示文稿中并调整它们的大小。我正在通过 Mac 上的 Rmd/Rstudio 执行此操作。我希望能够按照Yihui 的文档中的建议使用宏自定义大小

建议的调整大小的宏对我不起作用。

添加行:

.center[![trachoma](picsfigs/trachoma.jpg)]

工作正常,但添加 beforeInit: "macros.js" 并将宏添加到该文件 knitting 会产生空白演示文稿

---
title: "A Cool Presentation"
output:
  xaringan::moon_reader:
    css: [default, metropolis, metropolis-fonts]
    seal: true
    self_contained: true
    yolo: false
    beforeInit: "macros.js"
    nature:
      autoplay: 30000
---

- Hello world 

---

--- 

# new slide??

This works:


.center[![trachoma](picsfigs/trachoma.jpg)]

---

But this does not work:

.center[![:scale 50%](picsfigs/trachoma.jpg)]

Nor this

.center[![trachoma][:scale 50%](picsfigs/trachoma.jpg)]

one more slide

---

宏.js 文件:


remark.macros.scale = function (percentage) {
  var url = this;
  return '<img src="' + url + '" style="width: ' + percentage + '" />';
};

4

1 回答 1

4

您需要如下所示beforeInit: "macros.js"nature

---
title: "A Cool Presentation"
output:
  xaringan::moon_reader:
    css: [default, metropolis, metropolis-fonts]
    seal: true
    self_contained: true
    yolo: false
    nature:
      autoplay: 30000
      beforeInit: "macros.js"
---
于 2019-09-08T00:55:55.490 回答