我确定我忽略了一些明显的东西,但我想使用自定义 css 设计我生成的表格和 kable
。
您可以找到我的RMD
和CSS
文件的要点here .
我的目标是利用我发现的一些 Table CSS 示例 here .
当我运行我的报告时,我的表格如下所示:
但从上面的 CSS 示例来看,它应该如下图所示。
我的问题:我错过了什么,或者说 RMarkdown
无法实现这种级别的样式。
我的RMD
文件也如下所示:
---
title: "Test Table CSS"
output:
html_document:
theme: NULL
style: flat-table.css
---
I want to be able to style my tables with CSS. From the looks of it, I should be able to do that
through the use of `CSS` and `knitr:kable`.
```{r setup, echo=FALSE}
data(mtcars)
mt_head = head(mtcars[, 1:5])
```
I want to be able to style my table just like one found [here](http://codepen.io/njessen/pen/naLCv)
```{r echo=FALSE, results='asis'}
library(knitr)
kable(mt_head, "html", table.attr='class="flat-table"')
```
最佳答案
如果您使用下面的 .Rmd 文件和修改后的 CSS 文件,您可以获得所需的结果:
knitr::knit2html('my-report.RMD', stylesheet = 'flat-table.css')
结果如下:
这是更新后的 flat-table.css:
.flat-table {
display: block;
font-family: sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 115%;
overflow: auto;
width: auto;
}
th {
background-color: rgb(112, 196, 105);
color: white;
font-weight: normal;
padding: 20px 30px;
text-align: center;
}
td {
background-color: rgb(238, 238, 238);
color: rgb(111, 111, 111);
padding: 20px 30px;
}
关于css - 带有 CSS 的 Knitr 样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24254552/