如何在Rpres(R演示)幻灯片中添加全屏背景图像?

时间:2015-12-04 14:06:22

标签: r rstudio reveal.js slidify rpres

我想在使用Rstudio创建的R Presentation(Rpres)幻灯片中为一个或多个幻灯片添加全屏背景图像。我知道Rstudio的R Presentation幻灯片使用reveal.js框架来获得所有漂亮的眼睛效果,而我最接近实现我想要的就是遵循以下示例: https://www.uvm.edu/rsenr/vtcfwru/R/fledglings/14_Slideshows.html 并在幻灯片开始之前添加以下行:

--- &slidebg bg:url(atlas.png);background-size:cover
### Introduction: about this talk

Blah blah blah...

然而,虽然我看到图像,但它没有居中,图像只覆盖可用的文本区域 - 也就是说,图像看起来被裁剪,图像周围有很大的边距。如果有办法使图像居中并去除图像周围的边距,我会得到我想要的。在编写Rpres文件之后,我宁愿不必破解html。另外,我宁愿不用html重新编码我的幻灯片 - 我喜欢能够在Rstudio中的markdown中创建我的幻灯片。

我确实按照这里的建议尝试: Rpresentation in Rstudio - Make image fill out the whole screen 特别是关于使用http://github.com/regisb/reveal.js-fullscreen-img的评论,但我无法使其工作 - 或者提议的解决方案不能很好地与Rpres文件一起使用,或者README中的信息不足以让我一起破解让它运转的好处。

这似乎是一个非常简单的要求。当然,像在幻灯片中添加背景图片这样简单的事情也不会那么难吗?有什么想法吗?

1 个答案:

答案 0 :(得分:3)

从这里得到另一个答案:Rstudio 0.98.1028 add background image only to title slide

您可以拥有一个自定义的css文件,其中包含您的图像作为背景。我们称之为css-file.css:

<style>
/* Your other css */
    body {
      background-image: url(http://goo.gl/yJFbG4);
      background-position: center center;
      background-attachment: fixed;
      background-repeat: no-repeat;
      background-size: 100% 100%;
    }
.section .reveal .state-background {
    background-image: url(http://goo.gl/yJFbG4);
    background-position: center center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}
</style>

您可以在.Rpres文件的开头添加:

test
========================================================
author: 
date: 
css:css-file.css

这应该会在标题页上为您提供背景图像,并进行一些编辑,也可以显示以下页面。

HTH!

相关问题