blob: 27d1bb4df6d70ab32749bf85575ea51e762860cd [file] [log] [blame]
Hao Zhuc1450882018-10-03 17:56:26 -04001# Use Bootstrap Tables in gitbooks & epub
2
3## Gitbook
Hao Zhu68449202018-10-16 16:01:19 -04004Most 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)`.
Hao Zhuc1450882018-10-03 17:56:26 -04005
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 Zhub8098052018-10-08 16:57:43 -040014 latex_options = c("striped")
Hao Zhuc1450882018-10-03 17:56:26 -040015 ) %>%
16 column_spec(1, color = "red") %>%
17 add_header_above(c(" ", "Group A" = 2, "Group B" = 3))
18```
19
Hao Zhub8098052018-10-08 16:57:43 -040020**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`
21
22```
23bookdown::gitbook:
24 table_css: false
25```
Hao Zhuc1450882018-10-03 17:56:26 -040026
27## Epub
28Right 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,
29
30```
31bookdown::epub_book:
32 stylesheet: style.css
33```