在RMarkdown Slidy演示文稿中自定义CSS

时间:2017-06-06 05:22:48

标签: r rstudio r-markdown pandoc slidy

所以,关于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 个答案:

答案 0 :(得分:1)

问题发生后的很长时间,但对于子孙后代:

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

Rmarkdown:

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

输出:

enter image description here

注意:我发现此Customising CSS within RMarkdown Slidy Presentations无效:

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

答案 1 :(得分:0)

通过培养我对Bootstrap

的理解,我设法回答了我自己的问题

我需要使用整个Bootstrap目录,而不仅仅是我的WD中的Bootswatch主题css文件。然后,使用&#34; Slate&#34;或者以较新的主题替换默认的Bootstrap.css。

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