Knitr样式表与CSS [英] Knitr style table with CSS
问题描述
我相信我忽略了一些明显的东西,但我想用自定义css风格制作表格和 kable
。
I am sure that I am overlooking something obvious, but I want to style my tables produced and kable
with custom css.
您可以找到我的 RMD
和 CSS
文件的主旨此处。
You can find the gist of my RMD
and CSS
files here.
My goal was to leverage some of the Table CSS examples that I found here.
当我运行我的报告时,我的表格如下所示:
When I run my report, my table looks like this:
但从上面的CSS示例,它应该看起来像下面的图片。
but from the CSS example above, it should look like the image below.
>
我的问题:我缺少什么,或者是 RMarkdown
不能使用这个级别的样式。
My question: What am I missing, or is this level of styling not possible with 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文件下面,你可以获得你想要的结果:
If you take your .Rmd file and the modified CSS file below, you can obtain your desired result with:
knitr::knit2html('my-report.RMD', stylesheet = 'flat-table.css')
result:
Here's the result:
以下是更新的 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;
}
这篇关于Knitr样式表与CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!