| # Use Bootstrap Tables in gitbooks & epub |
| |
| ## Gitbook |
| Most of `kableExtra` tricks will work in `bookdown` except those requiring [`bootstrap`](http://getbootstrap.com/). By default, `rmarkdown` won't load `bootstrap` for you on gitbook as it's not necesary. In `kableExtra`, I used the [bootstrap 3.3.7 customization tool](https://getbootstrap.com/docs/3.3/customize/) and made a customized css copy. You can load it by setting `options(kableExtra.html.bsTable = T)`. |
| |
| ```{r} |
| library(kableExtra) |
| options(kableExtra.html.bsTable = T) |
| |
| mtcars[1:5, 1:5] %>% |
| kable(booktabs = T) %>% |
| kable_styling( |
| bootstrap_options = c("striped","hover", "bordered", "condensed"), |
| latex_options = c("striped") |
| ) %>% |
| column_spec(1, color = "red") %>% |
| add_header_above(c(" ", "Group A" = 2, "Group B" = 3)) |
| ``` |
| |
| **One very important note** here is that by default bookdown loads the gitbook table css on start up. It has some conflicts with `bootstrap` tables. As a result, some features like `hover` won't be able to work by default. To solve this problem, you need to use the latest version of `bookdown` (version >= 0.7.21) and turn off the `table_css` option under `bookdown::gitbook` in `_output.yml` |
| |
| ``` |
| bookdown::gitbook: |
| table_css: false |
| ``` |
| |
| ## Epub |
| Right now, it's impossible to load addition CSS through HTML dependency and this mechanism exists for a reason ( [See this issue I filed](https://github.com/rstudio/rmarkdown/issues/1457) ). You will have to manually load [this stylesheet](https://github.com/haozhu233/kableExtra/blob/master/inst/bootstrapTable-3.3.7/bootstrapTable.min.css) by putting it to a CSS file (such as "style.css") and load it in `_output.yml`. For example, |
| |
| ``` |
| bookdown::epub_book: |
| stylesheet: style.css |
| ``` |