在RMarkdown Slidy演示文稿中定制CSS

3

因此,在Stack Overflow上有一些问题,但没有解决这个特定问题的。

我想要使用自定义CSS模板来自定义我的RMarkdown/Slidy演示文稿,它是由RStudio创建的。

  • 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文档中的解决方法不起作用。该文档中的解决方案如下:
---
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

1
最后一个例子对我来说运行良好。请确保您有正确的缩进(每行开头2个空格)并且没有过时的空格或其他字符(例如哈希符号)。 - Martin Schmelzer
嘿,马丁,谢谢你的回复。不幸的是我仍然在苦苦挣扎,你能告诉我你把CSS文件放在哪里吗?我把它放在与我的rmd文件相同的目录中,即工作目录。(所有空格都已删除,上面的代码中的井号只是一个标志)。 - JohnL_10
与 Rmd 文件相同的文件夹。 - Martin Schmelzer
谢谢Martin。我再试了一次,这次出现了不同的问题,错误信息如下:pandoc: 无法获取./../fonts/glyphicons-halflings-regular.eot ./../fonts/glyphicons-halflings-regular.eot: openBinaryFile: 不存在(没有这个文件或目录) 错误:pandoc文档转换失败,错误代码为67 执行已停止 - JohnL_10
从错误信息的声音来看,或许需要在CSS文件中包含某些字体才能兼容?我正在使用 https://bootswatch.com/slate/bootstrap.css 上的一个主题。 - JohnL_10
2个回答

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

注意:我发现这个在RMarkdown Slidy演示中自定义CSS不起作用:
---
output:
  slidy_presentation:
    css: foo.css          
---

0

我通过深入了解Bootstrap来回答自己的问题。

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

这篇帖子(如何在Bootstrap 3中包含glyphicons)有一个最佳答案,完美地描述了它:


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接