用CSS块而不是CSS文件的R Markdown
我正在尝试更改针对滑动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,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不想使用CSS文件有原因吗?在YAML部分中添加它非常简单,您不必担心显示/不显示代码。
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.