I use the flextable
package to freeze the first row and the first column on an HTML report.
David Gohel recently added this option in flextable
dev version (0.8.3.13
) thanks to CSS comment.
However, I want to have the header cells with a white background.
I don't know the CSS language.
Anyone can help me having only the frozen header cells with a white background?
library(flextable)
dat <- lapply(1:30, function(x) rnorm(n = 50)) %>%
setNames(paste0("colname", 1:30)) %>%
as.data.frame()
ft_1 <- flextable(dat)
ft_1 <- set_table_properties(ft_1,
opts_html = list(
extra_css = ".tabwid tbody tr > :first-child {position: sticky;z-index: 1;left: 0;background: #ddd;}",
scroll = list(height="500px")))
ft_1
CodePudding user response:
Just append the .tabwid th {background-color: white; z-index: 2;}
in the extra_css
argument of set_table_properties
.
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(flextable)
library(magrittr)
dat <- lapply(1:30, function(x) rnorm(n = 50)) %>%
setNames(paste0("colname", 1:30)) %>%
as.data.frame()
ft_1 <- flextable(dat)
ft_1 <- set_table_properties(ft_1,
opts_html = list(
extra_css = ".tabwid tbody tr > :first-child {position: sticky;z-index: 1;left: 0;background: #ddd;} .tabwid th {background-color: white; z-index: 2;}",
scroll = list(height="500px")))
ft_1
```