【问题标题】:Customising CSS within RMarkdown Slidy Presentations在 RMarkdown Slidy 演示文稿中自定义 CSS
【发布时间】:2017-11-06 23:49:34
【问题描述】:

所以,有一些关于 SO 的问题,但似乎没有解决这个特定问题。

我希望使用自定义 CSS 模板自定义从 RStudio 创建的 RMarkdown/Slidy 演示文稿。

  • RStudio 已经允许使用内置的 Bootswatch 主题进行最少的自定义,因此可以访问 output: slidy presentation / theme: readable
  • 还有其他未内置的 Bootswatch 主题;具体来说,我可能想使用CyborgSlate,它们有漂亮的深色背景(而不是白色)

以下是使用自定义文件覆盖 Slidy CSS 的直观解决方案:

```{css}

<link href="bootstrap-slate.css" rel="stylesheet">

```

但是,它失败了:

pandoc.exe: Could not fetch .\../fonts/glyphicons-halflings-regular.eot
.\../fonts/glyphicons-halflings-regular.eot: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 67
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS segmentations.utf8.md --to slidy --from 
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --
output segmentations.html --smart --email-obfuscation none --self-contained --template "C:\Users\ME\Documents\R\R-3.3.3\library\rmarkdown\rmd\slidy\default.html" --include-in-header 
"C:\Users\ME\AppData\Local\Temp\RtmpGYLCFf\rmarkdown-str378022cf50b0.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --highlight-style pygments' had status 67 
Execution halted

欢迎提出任何建议。请注意,文档rMarkdown documentation 中的解决方案不起作用。解决方案复制到这里以供参考:

---
output:
  slidy_presentation:
    css: styles.css         ## 
---

Error in yaml::yaml.load(string, ...) : 
  Scanner error: mapping values are not allowed in this context at line 5, column 21
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load_utf8 -> <Anonymous> -> .Call
Execution halted

【问题讨论】:

  • 最后一个例子对我来说很好。确保您有正确的缩进(每行开头有 2 个空格),并且某处没有过时的空格或其他字符(如哈希)...
  • 嗨,马丁,感谢您的回复。不幸的是我还在挣扎,你能告诉我你把css文件放在哪里吗?我将它与我的 rmd 文件放在同一目录中,即在工作目录中。 (所有空格都被适当地删除了,上面代码中的哈希仅作为路标)。
  • 与 Rmd 文件在同一文件夹中。
  • 谢谢马丁。再次尝试,这次出现了不同的问题,错误消息现在显示为:pandoc: Could not fetch ./../fonts/glyphicons-halflings-regular.eot ./../fonts/glyphicons-halflings-regular.eot: openBinaryFile: does not exist (No such file or directory) Error: pandoc document conversion failed with error 67 Execution halted
  • 从错误信息的声音来看,也许css文件需要包含某些字体才能兼容?我正在使用来自 https://bootswatch.com/slate/bootstrap.css 的主题

标签: r rstudio r-markdown pandoc slidy


【解决方案1】:

通过加深对 Bootstrap 的理解,我设法回答了我自己的问题

我需要使用整个 Bootstrap 目录,而不仅仅是我的 WD 中的 Bootswatch 主题 css 文件。然后,要使用“Slate”或其他任何方式,需要将默认 Bootstrap.css 替换为新主题。

This Post (how to include glyphicons in bootstrap 3) 有一个完美描述它的最佳答案:

【讨论】:

    【解决方案2】:

    问题后很长时间,但为了后代:

    我发现这段代码主要使用您自己的示例。使用本地 css 文件。

    降价:

    ---
    title: "CSS and Slidy"
    author: Your name here
    date: 2018-05-31
    output: 
      slidy_presentation
    ---
    
    Outline
    ======================================================
    
    <link href="foo.css" rel="stylesheet">
    
    - Hello
    - World
    

    关联的css文件:

    body {
        color: blue;
    }
    
    h1 {
        color: green;
    }
    

    输出:

    注意:我发现这个 Customising CSS within RMarkdown Slidy Presentations 不起作用:

    ---
    output:
      slidy_presentation:
        css: foo.css          
    ---
    

    【讨论】:

      猜你喜欢
      • 2012-07-04
      • 1970-01-01
      • 2014-07-13
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多