【问题标题】:how to set up theorem environment in the Rmarkdown presentation如何在 Rmarkdown 演示文稿中设置定理环境
【发布时间】:2020-09-05 01:29:58
【问题描述】:

我是 Rmarkdown 新手,并计划使用 ioslides/slidy/xaringan 进行演示。

我以前用投影仪做演示。在投影仪中,我有专为数学定理设计的定理环境。我希望能够在 ioslides/slidy/xaringan 中使用这种格式。我知道我可以使用 $$...$$ 来包含乳胶代码并可以显示方程式。但是,这还不足以满足我的需求。

我也知道在 bookdown 中可以有定理环境。但我不知道如何在 ioslides/slidy/xaringan 输出格式。

【问题讨论】:

  • ioslides、slidy 和 xaringan 使用 MathJax,它不提供来自 amsmath 之类的定理环境。也许这有帮助:drz.ac/2013/01/17/latex-theorem-like-environments-for-the-web
  • 谢谢你的解释。我检查了那里的链接。它使用 Octopress。我不想用那个。我应该把这些 HTML css 代码放在 ioslides/slidy/xaringan 哪里?

标签: css r-markdown xaringan ioslides


【解决方案1】:

这对于在 cmets 中的讨论来说太长了,所以这里有一个答案。下面定义了一些受上述blog post中思想启发的样式:

styles.css

.theorem {
  display: block;
  font-style: italic;
  font-size: 24px;
  font-family: "Times New Roman";
  color: black;
}
.theorem::before {
  content: "Theorem. ";
  font-weight: bold;
  font-style: normal;
}
.theorem[text]::before {
  content: "Theorem (" attr(text) ") ";
}
.theorem p {
  display: inline;
}

要在 rmarkdown 演示文稿中使用这些样式,您可以通过 YAML 标头包含它们。对于 ioslides,它的工作方式如下(对于 slidy 和 xaringan 类似):

ioslides.Rmd(请注意,这要求 styles.css 与 ioslides.Rmd 位于同一文件夹中)

---
title: "Theorem demo"
output:
  ioslides_presentation:
    css: styles.css
---

您现在可以使用 theorem 类的 <div> 元素创建定理:

## CLT

<div class="theorem" text='CLT'>
  The CLT states that, as $n$ goes to infinity, the sample average $\bar{X}$
  converges in distribution to $\mathcal{N}(\mu,\sigma^2/n)$.
</div>

编辑:哥本哈根风格

精确地重新创建投影仪样式很麻烦,但是通过一些 CSS 技巧您可以接近。这是一个类似于theme: copenhagen 的示例。

.theorem {
  display: block;
  font-style: italic;
  font-size: 24px;
  font-family: "Times New Roman";
  color: black;
  border-radius: 10px;
  background-color: rgb(222,222,231);
  box-shadow: 5px 10px 8px #888888;
}
.theorem::before {
  content: "Theorem. ";
  font-weight: bold;
  font-style: normal;
  display: inline-block;
  width: -webkit-fill-available;
  color: white;
  border-radius: 10px 10px 0 0;
  padding: 10px 5px 5px 15px;
  background-color: rgb(38, 38, 134);
}
.theorem p {
  padding: 15px 15px 15px 15px;
}

【讨论】:

  • 这太好了。非常感谢你!我有一个额外的问题。请记住,在 Beamer 中,定理环境在语句周围有一个框架以及框架的一些背景颜色和阴影。你碰巧知道实现这一点的 HTML 代码吗?
  • 这正是我想要的。谢谢 !!!!!祝你一切顺利。
  • 我正在尝试将 style.css 包含在 xaringan 中。在定理环境中似乎无法识别乳胶代码。你知道如何解决这个问题吗?
  • 我愿意:这是因为 remark.js 会干扰 MathJax。如果您使用 \( ... \) 而不是 $ ... $ 来划分数学,它应该可以工作。 :)
  • 我明白了。谢谢!
猜你喜欢
  • 2017-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-17
相关资源
最近更新 更多