blob: 63a6ca128008fe5a8c295bdaef1dcf88ac1c0783 [file] [log] [blame]
Hao Zhuc1450882018-10-03 17:56:26 -04001# Use Bootstrap Tables in gitbooks & epub
2
3## Gitbook
4Most of `kableExtra` tricks will work in `bookdown` except those requires [`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)`.
5
6```{r}
7library(kableExtra)
8options(kableExtra.html.bsTable = T)
9
10mtcars[1:5, 1:5] %>%
11 kable(booktabs = T) %>%
12 kable_styling(
Hao Zhuc859dba2018-10-03 18:05:55 -040013 bootstrap_options = c("striped","hover", "bordered", "condensed"),
Hao Zhuc1450882018-10-03 17:56:26 -040014 latex_options = c("striped"),
15 full_width = F
16 ) %>%
17 column_spec(1, color = "red") %>%
18 add_header_above(c(" ", "Group A" = 2, "Group B" = 3))
19```
20
21However, very unfortunately, as we can see, the `hover` part is not working and the table still looks different from a regular bootstrap table. The reason is that gitbook defines its own way to style tables and some of its rules are conflicting with the one defined in bootstrap. For css, it's like once you load something, it's impossible to really unload it. As a result, unless there are some changes in `bookdown` (for example, we can replace the gitbook table part with bootstrap tables), there is nothing we can do here.
22
23## Epub
24Right now, it's impossible to load addition CSS through HTML dependency (due to a setting in rmarkdown). I will file an issue in `rmarkdown` and see if this is something that can be changed. In the mean time, to use bootstrap tables in Epub, 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,
25
26```
27bookdown::epub_book:
28 stylesheet: style.css
29```