在Xaringan(remark.js)演示文稿中,从本地目录包含和调整本地图片大小...(通过Rstudio在Mac上使用)

4
我希望您能够将本地目录中的图片/素材包含到Xaringan remark.js演示文稿中,并对其进行大小调整。我是通过Mac上的Rmd/Rstudio完成这个过程的。我希望能够使用宏来自定义大小,正如Yihui的文档所建议的那样。
然而,这些推荐的宏对我来说不起作用。
添加以下行:
.center[![trachoma](picsfigs/trachoma.jpg)]

这个功能正常运行,但添加 beforeInit: "macros.js" 并将宏添加到该文件的编织中会导致演示文稿为空白。

---
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

---

宏文件macros.js:


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

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"
---

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接