kableExtra - color of stripe

Viewed 675

It seems like this question has been asked in multiple places and has been answered, but it does not work for me. I would like to alternate color of kable. Color alternation works but shading is only of very light color. I would like to make it darker. Here is my example:

```{r test}
library(kableExtra)
my_df <- data.frame("col_1" = c(1,2,3), "col_2" = c(1,2,3))

knitr::kable(my_df)%>%
  kable_styling("striped", stripe_color="red")

```

Here is output: enter image description here

1 Answers

The help for kable_styling indicates stripe_color works only with latex output:

stripe_color LaTeX option allowing users to pick a different color for their strip lines. This option is not available in HTML.

One way to get alternating color backgrounds with html output is with row_spec (though there may be better ways):

library(kableExtra)

my_df <- data.frame("col_1" = c(1,2,3), "col_2" = c(1,2,3))

kable(my_df)%>%
  row_spec(seq(1,nrow(my_df),2), background="red")

Here's the output with a lighter background color and bootstrap styling for nicer-looking output:

kable(my_df)%>%
  row_spec(seq(1,nrow(my_df),2), background="#FF000020") %>% 
  kable_styling(full_width=FALSE)

enter image description here

Related