如何在knitr中突出显示表格的每一行?以下.Rmd的输出是全白表,而不是每隔一行灰色:
```{r setup, include=FALSE}
opts_chunk$set(cache=FALSE)
```
<style>
.myTable tr:nth-child(even) { /*(even) or (2n 0)*/
background: #EEEEEE;
}
.myTable tr:nth-child(odd) { /*(odd) or (2n 1)*/
background: #FFFFFF;
}
</style>
<TABLE border=1 class="myTable">
<TR> <TH> </TH> <TH> mpg </TH> <TH> cyl </TH> <TH> disp </TH> </TR>
<TR> <TD align="right"> Mazda RX4 </TD> <TD align="right"> 21.00 </TD> <TD align="right"> 6.00 </TD> <TD align="right"> 160.00 </TD> </TR>
<TR> <TD align="right"> Mazda RX4 Wag </TD> <TD align="right"> 21.00 </TD> <TD align="right"> 6.00 </TD> <TD align="right"> 160.00 </TD> </TR>
<TR> <TD align="right"> Datsun 710 </TD> <TD align="right"> 22.80 </TD> <TD align="right"> 4.00 </TD> <TD align="right"> 108.00 </TD> </TR>
<TR> <TD align="right"> Hornet 4 Drive </TD> <TD align="right"> 21.40 </TD> <TD align="right"> 6.00 </TD> <TD align="right"> 258.00 </TD> </TR>
<TR> <TD align="right"> Hornet Sportabout </TD> <TD align="right"> 18.70 </TD> <TD align="right"> 8.00 </TD> <TD align="right"> 360.00 </TD> </TR>
</TABLE>
答案 0 :(得分:6)
<style>
.myTable tr:nth-child(even) td{
background: #EEEEEE;
}
.myTable tr:nth-child(odd) td {
background: #FFFFFF;}
</style>
你必须添加td来覆盖body.td声明的效果。