Xaringan中的图像占位符

时间:2019-02-21 13:05:17

标签: r r-markdown xaringan

我正在使用xaringan中来自Yihui的R库来为演示文稿创建自定义模板。

其中一部分是创建自定义body幻灯片,如下图所示。

enter image description here

然后我将自定义CSS用于标题和正文:

  .body-yellow > h2 {
      font-size: 42px;
      text-transform: uppercase;
      padding-left: 
}

然后只需输入rmarkdown之类的

---
class: body-yellow

# Hello

## world

Hello world

然后填充幻灯片。

我的问题是,是否可以为上方模板中显示的图像创建占位符,可以在rmarkdown代码本身中对其进行调整?

我正在想象这样的代码:

---
class: body-yellow
background-images: url(./img/my_new_custom_image.png)

# Hello

## world

Hello world

以及CSS中的相关调整:

 .body-yellow > image {
    background-images: PLACEHOLDER
    position:right
    }

将如下更改图像:

enter image description here

请原谅我的CSS的无知,但我只是涉足这一领域。

1 个答案:

答案 0 :(得分:1)

您可以为body-yellow类设置全局背景图像,并使用特定幻灯片上的background-image属性覆盖它。这是一个最小的示例:

---
title: "Test"
output:
  xaringan::moon_reader:
    nature:
      ratio: "16:9"
---

class: body-yellow

```{css, echo=FALSE}
 .body-yellow > h2 {
  font-size: 42px;
  text-transform: uppercase;
  padding-left: 50px;
}
.body-yellow {
  background-image: url(https://i.stack.imgur.com/OSrg8t.png);
  background-size: contain;
}
```


## Default background

---
class: body-yellow
background-image: url(https://i.stack.imgur.com/X1C2Bt.png)

## A custom background

Use a custom background to override the default