5

I'm currently using the following kable_styling() from kableExtra:

  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))

I can set the table style to kable in my R Markdown document in the YAML metadata as follows:

output:
  html_document:
    df_print: kable

But this just outputs all my tables in plain HTML. I'm not sure how to apply my kable_styling() to all chunks. At the moment I have to write the following out in full in every chunk:

df %>%
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))

Question

How can I apply my kable_styling() to all code chunks without having to write it out in all code chunks?

pomodoro
  • 297
  • 3
  • 12
  • You may want to learn the CSS for the styles that kable is applying (I.e. the style of [striped rows](https://stackoverflow.com/questions/3084261/alternate-table-row-color-using-css/3084318#3084318), [hover](https://stackoverflow.com/questions/31360242/column-and-row-highlight-on-hover-in-striped-table-in-css)), then you could use CSS in the header (or an external CSS file) to style all of the tables simultaneously. – Wil Apr 12 '19 at 01:38
  • 1
    I've tried doing the same thing, and wrote about it here: https://telethonkids.wordpress.com/2019/02/12/automating-r-markdown-tables-with-hooks/ it doesn't quite fix the problem, but it's a start. – Paul Apr 12 '19 at 03:29
  • 2
    Possible duplicate of [How to set knitr::kable() global options in markdown for reuse](https://stackoverflow.com/questions/54168558/how-to-set-knitrkable-global-options-in-markdown-for-reuse) – user2554330 Apr 12 '19 at 10:51
  • Any improvements so far ? – César Arquero Cabral Jan 19 '22 at 10:24

0 Answers0