如何为knitr :: kable指定表条纹颜色? [英] How to specify table stripe colors for knitr::kable?

查看:220
本文介绍了如何为knitr :: kable指定表条纹颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此人如何制作此链接?看起来他们没有向kable传递任何参数.

How was this person able to make the tables shown in this link? It doesn't look like they were passing any arguments to kable.

这里是示例:

推荐答案

kable表的样式由CSS文件控制. tbody可用于更改表内容的颜色,而thead可以更改标题.

The styles of kable tables are controlled by CSS file. tbody can be used to change the colour of the content of the table, with thead able to change the header.

如Lee S所示,您可以创建一个外部CSS文件.但是,您也可以将CSS直接包含在R Markdown文件中,因为markdown接受原始HTML并将其通过原样传递. 请参阅此处有关更多详细信息

As shown by Lee S, you can create an external CSS file. However, you can also include the CSS directly within the R Markdown file, as markdown accepts raw HTML and passes it through unaltered. See here for some more details

这是一个完全可复制的示例:

Here is a full reproducible example:

---
output: html_document
---

# Test Project

<style>
   tbody tr:nth-child(odd){
    background-color: #F7FBFF;
  }
</style>


```{r}
knitr::kable(mtcars[1:5, 1:5])
```

本指南对表格元素进行了很好的说明,由CSS控制.

This guide provides a good explanation of the table elements which can be controlled by CSS.

这篇关于如何为knitr :: kable指定表条纹颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆