用CSS块而不是CSS文件的R Markdown

发布于 2025-02-01 08:01:08 字数 1281 浏览 1 评论 0原文

我正在尝试更改针对滑动HTML的R Markdown中表标头的背景颜色。我对输出使用Xtable,并在其他方法上使用 css 最简单。我决定与a csss chunk >而不是 css 文件。

---
title: "Test"
output: slidy_presentation
---

```{r setup, include = F}
library(xtable)
```

css

```{css, header, echo = F}
th {
  background: orange;
}
```

表输出

# Table output

```{r table, results = "asis", echo = F}

df <- data.frame("Col.A" = 1:3, "Col.B" = 4:6)

print(xtable(df), type = "HTML", include.rownames = F)

```

以下是带有橙色标头的表。但是,使用{CSS,echo = f},标题页(#1)和实际输出(#3)之间有一个空白页。我还注意到,在输出的左上角,它读取表输出(3/2)。 3/2 ...在空白页面上,它读取表输出(2/2)。而且

如果我使用{CSS,include = f},空白页面已经消失(只是标题页和输出页面),则表标头的背景颜色也是如此。

我在另一个线程 css 块,没有任何使用这种方法的空白页。如何在没有空白页面的情况下更改表标头的背景颜色?谢谢你!

I am trying to change the background color of table headers in R Markdown knitted to Slidy HTML. I use xtable for the output and found it easiest with CSS over other methods. I decided to go with a CSS chunk instead of a CSS file.

---
title: "Test"
output: slidy_presentation
---

```{r setup, include = F}
library(xtable)
```

CSS chunk

```{css, header, echo = F}
th {
  background: orange;
}
```

Table output

# Table output

```{r table, results = "asis", echo = F}

df <- data.frame("Col.A" = 1:3, "Col.B" = 4:6)

print(xtable(df), type = "HTML", include.rownames = F)

```

Here's the table with headers in orange. However, with {css, echo = F}, there's a blank page between the title page (#1) and the actual output (#3). I also notice, on the upper left corner in output, it reads Table output (3/2). 3/2... On the blank page, it reads Table output (2/2). And there is not a 3/2 in the dropdown. I need to mouse click to advance to page 3 (the actual output). In the Table of Contents, however, there are three pages, Test (the title page), Test(2), and Table output.

If I use {css, include = F}, the blank page was gone (just the title page and the output page) and so was the background color of the table headers.

I found in another thread, someone also recommended a CSS chunk without any indication of a blank page with such a method. How do I change the background color of the table headers without a blank page? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落画卷 2025-02-08 08:01:08

您不想使用CSS文件有原因吗?在YAML部分中添加它非常简单,您不必担心显示/不显示代码。

---
title: "Test"
output: 
  slidy_presentation:
    css: style.css
---

Is there a reason why you don't want to use a css file? Adding it in the yaml section is so easy and you don't have to worry about showing/not showing the code.

---
title: "Test"
output: 
  slidy_presentation:
    css: style.css
---
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文