【问题标题】:Override reveal.js in R Markdown presentation在 R Markdown 演示文稿中覆盖reveal.js
【发布时间】:2017-03-15 13:16:53
【问题描述】:

我正在尝试在 rmarkdown 中整合一个显示 js 演示文稿,但在覆盖默认 css 主题时遇到了麻烦。我想从我的绘图图像中删除边框。根据文档,这应该可以工作:

但它没有,我猜这是因为这个覆盖不是更具体。但我的问题是我通常的增加特异性的方法也不起作用:

## Slide with Plot
<section class = "no-border">
```{r pressure}
plot(pressure)
```
</section>

这是 YAML 标头:

title: "Title"
author: "..."
date: '`r paste(format(Sys.Date(),"%d")," ", mymonths[sys.man], ", ",
                format(Sys.Date(),"%Y"), sep = "")`'
output:
  revealjs::revealjs_presentation:
    incremental: true
    includes:
      in_header: slidy_bootstrap_header.html
      css: slidyStandard.css

这是 css 覆盖:

section.no-border > img {
  background:none; 
  border:none; 
  box-shadow:none;
 }

有谁知道我做错了什么?

【问题讨论】:

  • 你确定 YAML 中的缩进是正确的吗?您是否尝试将 !important 添加到您的 CSS 类?
  • @MartinSchmelzer 我希望如此,没有错误,但这并不意味着什么,也添加了它。编辑:试过了!重要的是,也没有用
  • 为了完整起见,您还可以为 .no-border 添加 CSS 样式 :)

标签: css r rstudio r-markdown reveal.js


【解决方案1】:

我意识到我将自定义 CSS 放在了 YAML 标头中的错误位置。因此,它没有工作。

以下是自定义 css 的可重现代码:

---
title: "Untitled"
output: 
  revealjs::revealjs_presentation:
    css: custom2.css
---

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Slide with R Code and Output

```{r}
summary(cars)
```

## Slide with Plot

```{r, echo=FALSE}
plot(cars)
```

还有css:

.reveal section img {
  margin: 15px 0px;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  box-shadow: none; 
  }

【讨论】:

    【解决方案2】:

    问题似乎是,您的&lt;section&gt; 标记没有被包裹在源代码及其输出周围。你可以做的是使用 jQuery:

    ---
    title: "Title"
    author: "..."
    output:
      revealjs::revealjs_presentation:
        incremental: true
        includes:
          css: slidyStandard.css
    ---
    
    <!-- Include jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    
    <!-- Add class to img elements -->
    <script type="text/javascript">
    $(document).ready(function() {
      $elms = $('p > img');
      $elms.addClass('no-border');
    });
    </script>
    
    <!-- define no-border class -->
    <style>
    .no-border {
      border: 0px !important;
    }
    </style>
    
    ```{r pressure}
    plot(pressure)
    ```
    

    【讨论】:

    • 我应该将它添加到头部 (in_header:) 还是正文之前 (before_body:)?
    • 您可以在 YAML 块之后和第一张幻灯片之前添加它。
    • 好的-谢谢!它被插入到 html 中,但似乎没有执行,因为 img-tags 没有改变。
    • 这很奇怪。我添加了一张图片来向您展示我得到的结果。我还添加了 Rmd 的全部内容。情节周围的黑色大边框消失了(一些阴影仍然存在)。
    • 是的 - 很奇怪,但错误似乎在我的完整演示文稿中,因为我让你的代码也能正常工作......可能是覆盖覆盖的东西...... :) 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 2015-09-18
    • 2020-08-09
    • 2017-11-27
    相关资源
    最近更新 更多