improve lightable's look on add_header_above/group_rows
improve documentation
diff --git a/docs/awesome_table_in_html.Rmd b/docs/awesome_table_in_html.Rmd
index 2a7250a..43f6f1d 100644
--- a/docs/awesome_table_in_html.Rmd
+++ b/docs/awesome_table_in_html.Rmd
@@ -47,13 +47,10 @@
dt <- mtcars[1:5, 1:6]
```
-> **Key Update:** In the latest version of this package (1.2+), we provide a wrapper funciton to the original
+> **Key Update:** In the latest version of this package (1.2+), we provide a wrapper funciton `kbl` to the original `kable` function with detailed documentation of all the hidden html/latex options. It also does auto-formatting check in every function call instead of relying on the global environement variable. As a result, it also solves an issue for multi-format R Markdown documents. I encourage you start to use the new `kbl` function for all its convenience but the support for the original `kable` function is still there. In this doc, we will use `kbl` instead of `kable`.
-When you are using `kable()`, if you don't specify `format`, by default it will generate a markdown table and let pandoc handle the conversion from markdown to HTML/PDF. This is the most favorable approach to render most simple tables as it is format independent. If you switch from HTML to pdf, you basically don't need to change anything in your code. However, markdown doesn't support complex table. For example, if you want to have a double-row header table, markdown just cannot provide you the functionality you need. As a result, when you have such a need, you should **define `format` in `kable()`** as either "html" or "latex". *You can also define a global option at the beginning using `options(knitr.table.format = "html")` so you don't repeat the step everytime.*
-**Starting from `kableExtra` 0.9.0**, when you load this package (`library(kableExtra)`), it will automatically set up the global option 'knitr.table.format' based on your current environment. Unless you are rendering a PDF, `kableExtra` will try to render a HTML table for you. **You no longer need to manually set either the global option or the `format` option in each `kable()` function**. I'm still including the explanation above here in this vignette so you can understand what is going on behind the scene. Note that this is only an global option. You can manually set any format in `kable()` whenever you want. I just hope you can enjoy a peace of mind in most of your time.
-
-You can disable this behavior by setting `options(kableExtra.auto_format = FALSE)` before you load `kableExtra`.
+**This paragraph is a little outdated. It's here only for education purpose because it's helpful to understand how `kable` works under the hood**. When you are using `kable()`, if you don't specify `format`, by default it will generate a markdown table and let pandoc handle the conversion from markdown to HTML/PDF. This is the most favorable approach to render most simple tables as it is format independent. If you switch from HTML to pdf, you basically don't need to change anything in your code. However, markdown doesn't support complex table. For example, if you want to have a double-row header table, markdown just cannot provide you the functionality you need. As a result, when you have such a need, you should **define `format` in `kable()`** as either "html" or "latex". *You can also define a global option at the beginning using `options(knitr.table.format = "html")` so you don't repeat the step everytime.* **Starting from `kableExtra` 0.9.0**, when you load this package (`library(kableExtra)`), it will automatically set up the global option 'knitr.table.format' based on your current environment. Unless you are rendering a PDF, `kableExtra` will try to render a HTML table for you. **You no longer need to manually set either the global option or the `format` option in each `kable()` function**. I'm still including the explanation above here in this vignette so you can understand what is going on behind the scene. Note that this is only an global option. You can manually set any format in `kable()` whenever you want. I just hope you can enjoy a peace of mind in most of your time. You can disable this behavior by setting `options(kableExtra.auto_format = FALSE)` before you load `kableExtra`.
```{r}
# If you are using kableExtra < 0.9.0, you are recommended to set a global option first.
@@ -64,14 +61,14 @@
## Basic HTML table
Basic HTML output of `kable` looks very crude. To the end, it's just a plain HTML table without any love from css.
```{r}
-kable(dt)
+kbl(dt)
```
## Bootstrap theme
When used on a HTML table, `kable_styling()` will automatically apply twitter bootstrap theme to the table. Now it should looks the same as the original pandoc output (the one when you don't specify `format` in `kable()`) but this time, you are controlling it.
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_styling()
```
@@ -80,37 +77,37 @@
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_paper("hover")
```
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_classic()
```
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_classic_2()
```
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_minimal()
```
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_material(c("striped", "hover"))
```
```{r}
dt %>%
- kable() %>%
+ kbl() %>%
kable_material_dark()
```
@@ -124,39 +121,39 @@
For example, to add striped lines (alternative row colors) to your table and you want to highlight the hovered row, you can simply type:
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling(bootstrap_options = c("striped", "hover"))
```
The option `condensed` can also be handy in many cases when you don't want your table to be too large. It has slightly shorter row height.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
```
Tables with option `responsive` looks the same with others on a large screen. However, on a small screen like phone, they are horizontally scrollable. Please resize your window to see the result.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
```
## Full width?
By default, a bootstrap table takes 100% of the width. It is supposed to use together with its grid system to scale the table properly. However, when you are writing a rmarkdown document, you probably don't want to write your own css/or grid. For some small tables with only few columns, a page wide table looks awful. To make it easier, you can specify whether you want the table to have `full_width` or not in `kable_styling`. By default, `full_width` is set to be `TRUE` for HTML tables (note that for LaTeX, the default is `FALSE` since I don't want to change the "common" looks unless you specified it.)
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_paper(bootstrap_options = "striped", full_width = F)
```
## Position
Table Position only matters when the table doesn't have `full_width`. You can choose to align the table to `center`, `left` or `right` side of the page
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "left")
```
Becides these three common options, you can also wrap text around the table using the `float-left` or `float-right` options.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "float_right")
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet mauris in ex ultricies elementum vel rutrum dolor. Phasellus tempor convallis dui, in hendrerit mauris placerat scelerisque. Maecenas a accumsan enim, a maximus velit. Pellentesque in risus eget est faucibus convallis nec at nulla. Phasellus nec lacinia justo. Morbi fermentum, orci id varius accumsan, nibh neque porttitor ipsum, consectetur luctus risus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam non vulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sed congue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Nam accumsan urna risus, non feugiat odio vehicula eget.
@@ -164,7 +161,7 @@
## Font size
If one of your tables is huge and you want to use a smaller font size for that specific table, you can use the `font_size` option.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling(bootstrap_options = "striped", font_size = 7)
```
@@ -172,7 +169,7 @@
If you happened to have a very long table, you may consider to use this `fixed_header` option to fix the header row on top as your readers scroll. By default, the background is set to white. If you need a different color, you can set `fixed_header = list(enabled = T, background = "red")`.
```{r}
-kable(mtcars[1:10, 1:5]) %>%
+kbl(mtcars[1:10, 1:5]) %>%
kable_styling(fixed_thead = T)
```
@@ -192,7 +189,7 @@
)
)
-kable(text_tbl) %>%
+kbl(text_tbl) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, border_right = T) %>%
column_spec(2, width = "30em", background = "yellow")
@@ -202,7 +199,7 @@
```{r}
mtcars[1:8, 1:8] %>%
- kable() %>%
+ kbl() %>%
kable_paper(full_width = F) %>%
column_spec(2, color = spec_color(mtcars$mpg[1:8]),
link = "https://haozhu233.github.io/kableExtra") %>%
@@ -217,7 +214,7 @@
Similar with `column_spec`, you can define specifications for rows. Currently, you can either bold or italicize an entire row. Note that, similar with other row-related functions in `kableExtra`, for the position of the target row, you don't need to count in header rows or the group labeling rows.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
column_spec(5:7, bold = T) %>%
row_spec(3:5, bold = T, color = "white", background = "#D7261E")
@@ -228,7 +225,7 @@
## Header Rows
One special case of `row_spec` is that you can specify the format of the header row via `row_spec(row = 0, ...)`.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
row_spec(0, angle = -45)
```
@@ -256,7 +253,7 @@
c("#666666", "#999999", "#BBBBBB")))
) %>%
select(car, mpg, cyl) %>%
- kable(format = "html", escape = F) %>%
+ kbl(format = "html", escape = F) %>%
kable_styling("striped", full_width = F)
```
@@ -274,7 +271,7 @@
Species, color = "white", bold = T,
background = spec_color(1:10, end = 0.9, option = "A", direction = -1)
)) %>%
- kable(escape = F, align = "c") %>%
+ kbl(escape = F, align = "c") %>%
kable_styling(c("striped", "condensed"), full_width = F)
```
@@ -339,7 +336,7 @@
title = NULL, # title will add a Title Panel on top
position = popover_dt$position
))
-kable(popover_dt, escape = FALSE) %>%
+kbl(popover_dt, escape = FALSE) %>%
kable_styling("striped", full_width = FALSE)
```
@@ -364,7 +361,7 @@
hp = color_bar("lightgreen")(hp)
) %>%
select(car, everything()) %>%
- kable(escape = F) %>%
+ kbl(escape = F) %>%
kable_styling("hover", full_width = F) %>%
column_spec(5, width = "3cm") %>%
add_header_above(c(" ", "Hello" = 2, "World" = 2))
@@ -374,15 +371,15 @@
## Add header rows to group columns
Tables with multi-row headers can be very useful to demonstrate grouped data. To do that, you can pipe your kable object into `add_header_above()`. The header variable is supposed to be a named character with the names as new column names and values as column span. For your convenience, if column span equals to 1, you can ignore the `=1` part so the function below can be written as `add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)).
```{r}
-kable(dt) %>%
- kable_styling("striped") %>%
+kbl(dt) %>%
+ kable_classic() %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2))
```
In fact, if you want to add another row of header on top, please feel free to do so.
```{r}
-kable(dt) %>%
- kable_styling(c("striped", "bordered")) %>%
+kbl(dt) %>%
+ kable_paper() %>%
add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>%
add_header_above(c(" ", "Group 4" = 4, "Group 5" = 2)) %>%
add_header_above(c(" ", "Group 6" = 6))
@@ -391,7 +388,7 @@
## Group rows via labeling
Sometimes we want a few rows of the table being grouped together. They might be items under the same topic (e.g., animals in one species) or just different data groups for a categorical variable (e.g., age < 40, age > 40). With the function `group_rows()`/`pack_rows()` in `kableExtra`, this kind of task can be completed in one line. Please see the example below. Note that when you count for the start/end rows of the group, you don't need to count for the header rows nor other group label rows. You only need to think about the row numbers in the "original R dataframe".
```{r}
-kable(mtcars[1:10, 1:6], caption = "Group Rows") %>%
+kbl(mtcars[1:10, 1:6], caption = "Group Rows") %>%
kable_styling("striped", full_width = F) %>%
pack_rows("Group 1", 4, 7) %>%
pack_rows("Group 2", 8, 10)
@@ -400,14 +397,14 @@
Another way to use `pack_rows` is to provide an grouping index, similar with `add_header_above()`. This feature is only available in kableExtra > 0.5.2.
```{r, eval = F}
# Not evaluated. This example generates the same table as above.
-kable(mtcars[1:10, 1:6], caption = "Group Rows") %>%
+kbl(mtcars[1:10, 1:6], caption = "Group Rows") %>%
kable_styling("striped", full_width = F) %>%
pack_rows(index = c(" " = 3, "Group 1" = 4, "Group 2" = 3))
```
For advanced users, you can even define your own css for the group labeling.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
pack_rows("Group 1", 3, 5, label_row_css = "background-color: #666; color: #fff;")
```
@@ -434,7 +431,7 @@
Unlike `pack_rows()`, which will insert a labeling row, sometimes we want to list a few sub groups under a total one. In that case, `add_indent()` is probably more apporiate.
For advanced users, you can even define your own css for the group labeling.
```{r}
-kable(dt) %>%
+kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
add_indent(c(1, 3, 5))
```
@@ -447,7 +444,7 @@
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
-kable(collapse_rows_dt, align = "c") %>%
+kbl(collapse_rows_dt, align = "c") %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T) %>%
collapse_rows(columns = 1:2, valign = "top")
@@ -461,8 +458,8 @@
There are four notation systems in `footnote`, namely `general`, `number`, `alphabet` and `symbol`. The last three types of footnotes will be labeled with corresponding marks while `general` won't be labeled. You can pick any one of these systems or choose to display them all for fulfill the APA table footnotes requirements.
```{r}
-kable(dt, align = "c") %>%
- kable_styling(full_width = F) %>%
+kbl(dt, align = "c") %>%
+ kable_classic(full_width = F) %>%
footnote(general = "Here is a general comments of the table. ",
number = c("Footnote 1; ", "Footnote 2; "),
alphabet = c("Footnote A; ", "Footnote B; "),
@@ -473,7 +470,7 @@
You can also specify title for each category by using the `***_title` arguments. Default value for `general_title` is "Note: " and "" for the rest three. You can also change the order using `footnote_order`. You can even display footnote as chunk texts (default is as a list) using `footnote_as_chunk`. The font format of the titles are controlled by `title_format` with options including "italic" (default), "bold" and "underline".
```{r}
-kable(dt, align = "c") %>%
+kbl(dt, align = "c") %>%
kable_styling(full_width = F) %>%
footnote(general = "Here is a general comments of the table. ",
number = c("Footnote 1; ", "Footnote 2; "),
@@ -493,7 +490,7 @@
footnote_marker_symbol(1))
row.names(dt_footnote)[4] <- paste0(row.names(dt_footnote)[4],
footnote_marker_alphabet(1))
-kable(dt_footnote, align = "c",
+kbl(dt_footnote, align = "c",
# Remember this escape = F
escape = F) %>%
kable_styling(full_width = F) %>%
@@ -510,7 +507,7 @@
When you use `scroll_box`, you can specify either `height` or `width`. When you specify `height`, you will get a vertically scrollable box and vice versa. If you specify both, you will get a two-way scrollable box.
```{r}
-kable(cbind(mtcars, mtcars)) %>%
+kbl(cbind(mtcars, mtcars)) %>%
kable_styling() %>%
scroll_box(width = "500px", height = "200px")
```
@@ -520,7 +517,7 @@
You can also specify width using a percentage.
```{r}
-kable(cbind(mtcars, mtcars)) %>%
+kbl(cbind(mtcars, mtcars)) %>%
add_header_above(c("a" = 5, "b" = 18)) %>%
kable_styling() %>%
scroll_box(width = "100%", height = "200px")
@@ -531,7 +528,7 @@
## Save HTML table directly
If you need to save those HTML tables but you don't want to generate them through rmarkdown, you can try to use the `save_kable()` function. You can choose whether to let those HTML files be self contained (default is yes). Self contained files packed CSS into the HTML file so they are quite large when there are many.
```{r, eval=FALSE}
-kable(mtcars) %>%
+kbl(mtcars) %>%
kable_styling() %>%
save_kable(file = "table1.html", self_contained = T)
```
diff --git a/docs/awesome_table_in_html.html b/docs/awesome_table_in_html.html
index 28f5862..1a7cb46 100644
--- a/docs/awesome_table_in_html.html
+++ b/docs/awesome_table_in_html.html
@@ -1332,8 +1332,8 @@
margin-left: 5px;
margin-right: 5px;
}
-.lightable-minimal thead tr th {
-border-bottom: 2px solid black;
+.lightable-minimal thead tr:last-child th {
+border-bottom: 2px solid #00000050;
empty-cells: hide;
}
.lightable-minimal tbody tr:first-child td {
@@ -1342,12 +1342,11 @@
.lightable-minimal.lightable-hover tbody tr:hover {
background-color: #f5f5f5;
}
-.lightable-minimal.lightable-striped tr:nth-child(even) {
+.lightable-minimal.lightable-striped tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
.lightable-classic {
border-top: 2px solid #111111;
-border-bottom: 2px solid #111111;
width: 100%;
margin-bottom: 10px;
}
@@ -1362,15 +1361,17 @@
.lightable-classic thead tr:last-child th {
border-bottom: 1px solid #111111;
}
+.lightable-classic tbody tr:last-child td {
+border-bottom: 2px solid #111111;
+}
.lightable-classic.lightable-hover tbody tr:hover {
background-color: #F9EEC1;
}
-.lightable-classic.lightable-striped tr:nth-child(even) {
+.lightable-classic.lightable-striped tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
.lightable-classic-2 {
border-top: 3px double #111111;
-border-bottom: 3px double #111111;
width: 100%;
margin-bottom: 10px;
}
@@ -1382,13 +1383,16 @@
padding-left: 5px;
padding-right: 5px;
}
+.lightable-classic-2 tbody tr:last-child td {
+border-bottom: 3px double #111111;
+}
.lightable-classic-2 thead tr:last-child th {
border-bottom: 1px solid #111111;
}
.lightable-classic-2.lightable-hover tbody tr:hover {
background-color: #F9EEC1;
}
-.lightable-classic-2.lightable-striped tr:nth-child(even) {
+.lightable-classic-2.lightable-striped tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
.lightable-material {
@@ -1414,10 +1418,10 @@
.lightable-material.lightable-hover tbody tr:hover {
background-color: #f5f5f5;
}
-.lightable-material.lightable-striped tr:nth-child(even) {
+.lightable-material.lightable-striped tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
-.lightable-material.lightable-striped td {
+.lightable-material.lightable-striped tbody td {
border: 0;
}
.lightable-material.lightable-striped thead tr:last-child th {
@@ -1449,10 +1453,10 @@
.lightable-material-dark.lightable-hover tbody tr:hover {
background-color: #FFFFFF12;
}
-.lightable-material-dark.lightable-striped tr:nth-child(even) {
+.lightable-material-dark.lightable-striped tbody tr:nth-child(even) {
background-color: #FFFFFF12;
}
-.lightable-material-dark.lightable-striped td {
+.lightable-material-dark.lightable-striped tbody td {
border: 0;
}
.lightable-material-dark.lightable-striped thead tr:last-child th {
@@ -1462,7 +1466,7 @@
width: 100%;
margin-bottom: 10px;
}
-.lightable-paper th {
+.lightable-paper thead tr:last-child th {
color: #999;
vertical-align: bottom;
border-bottom: 1px solid #00000020;
@@ -1478,10 +1482,10 @@
.lightable-paper.lightable-hover tbody tr:hover {
background-color: #F9EEC1;
}
-.lightable-paper.lightable-striped tr:nth-child(even) {
+.lightable-paper.lightable-striped tbody tr:nth-child(even) {
background-color: #00000008;
}
-.lightable-material-dark.lightable-striped td {
+.lightable-paper.lightable-striped tbody td {
border: 0;
}
</style>
@@ -1746,23 +1750,19 @@
<h1>Getting Started</h1>
<p>Here we are using the first few columns and rows from dataset <code>mtcars</code></p>
<pre class="r"><code>library(knitr)
-library(kableExtra)</code></pre>
-<pre><code>##
-## Attaching package: 'kableExtra'</code></pre>
-<pre><code>## The following object is masked from 'package:knitr':
-##
-## kable</code></pre>
-<pre class="r"><code>dt <- mtcars[1:5, 1:6]</code></pre>
-<p>When you are using <code>kable()</code>, if you don’t specify <code>format</code>, by default it will generate a markdown table and let pandoc handle the conversion from markdown to HTML/PDF. This is the most favorable approach to render most simple tables as it is format independent. If you switch from HTML to pdf, you basically don’t need to change anything in your code. However, markdown doesn’t support complex table. For example, if you want to have a double-row header table, markdown just cannot provide you the functionality you need. As a result, when you have such a need, you should <strong>define <code>format</code> in <code>kable()</code></strong> as either “html” or “latex”. <em>You can also define a global option at the beginning using <code>options(knitr.table.format = "html")</code> so you don’t repeat the step everytime.</em></p>
-<p><strong>Starting from <code>kableExtra</code> 0.9.0</strong>, when you load this package (<code>library(kableExtra)</code>), <span style=" font-weight: bold; color: white !important;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: #d9230f !important;">it will automatically set up the global option ‘knitr.table.format’ based on your current environment</span>. Unless you are rendering a PDF, <code>kableExtra</code> will try to render a HTML table for you. <strong>You no longer need to manually set either the global option or the <code>format</code> option in each <code>kable()</code> function</strong>. I’m still including the explanation above here in this vignette so you can understand what is going on behind the scene. Note that this is only an global option. You can manually set any format in <code>kable()</code> whenever you want. I just hope you can enjoy a peace of mind in most of your time.</p>
-<p>You can disable this behavior by setting <code>options(kableExtra.auto_format = FALSE)</code> before you load <code>kableExtra</code>.</p>
+library(kableExtra)
+dt <- mtcars[1:5, 1:6]</code></pre>
+<blockquote>
+<p><strong>Key Update:</strong> In the latest version of this package (1.2+), we provide a wrapper funciton <code>kbl</code> to the original <code>kable</code> function with detailed documentation of all the hidden html/latex options. It also does auto-formatting check in every function call instead of relying on the global environement variable. As a result, it also solves an issue for multi-format R Markdown documents. I encourage you start to use the new <code>kbl</code> function for all its convenience but the support for the original <code>kable</code> function is still there. In this doc, we will use <code>kbl</code> instead of <code>kable</code>.</p>
+</blockquote>
+<p><strong>This paragraph is a little outdated. It’s here only for education purpose because it’s helpful to understand how <code>kable</code> works under the hood</strong>. When you are using <code>kable()</code>, if you don’t specify <code>format</code>, by default it will generate a markdown table and let pandoc handle the conversion from markdown to HTML/PDF. This is the most favorable approach to render most simple tables as it is format independent. If you switch from HTML to pdf, you basically don’t need to change anything in your code. However, markdown doesn’t support complex table. For example, if you want to have a double-row header table, markdown just cannot provide you the functionality you need. As a result, when you have such a need, you should <strong>define <code>format</code> in <code>kable()</code></strong> as either “html” or “latex”. <em>You can also define a global option at the beginning using <code>options(knitr.table.format = "html")</code> so you don’t repeat the step everytime.</em> <strong>Starting from <code>kableExtra</code> 0.9.0</strong>, when you load this package (<code>library(kableExtra)</code>), it will automatically set up the global option ‘knitr.table.format’ based on your current environment. Unless you are rendering a PDF, <code>kableExtra</code> will try to render a HTML table for you. <strong>You no longer need to manually set either the global option or the <code>format</code> option in each <code>kable()</code> function</strong>. I’m still including the explanation above here in this vignette so you can understand what is going on behind the scene. Note that this is only an global option. You can manually set any format in <code>kable()</code> whenever you want. I just hope you can enjoy a peace of mind in most of your time. You can disable this behavior by setting <code>options(kableExtra.auto_format = FALSE)</code> before you load <code>kableExtra</code>.</p>
<pre class="r"><code># If you are using kableExtra < 0.9.0, you are recommended to set a global option first.
# options(knitr.table.format = "html")
## If you don't define format here, you'll need put `format = "html"` in every kable function.</code></pre>
<div id="basic-html-table" class="section level2">
<h2>Basic HTML table</h2>
<p>Basic HTML output of <code>kable</code> looks very crude. To the end, it’s just a plain HTML table without any love from css.</p>
-<pre class="r"><code>kable(dt)</code></pre>
+<pre class="r"><code>kbl(dt)</code></pre>
<table>
<thead>
<tr>
@@ -1909,9 +1909,9 @@
</div>
<div id="bootstrap-theme" class="section level2">
<h2>Bootstrap theme</h2>
-<p>When used on a HTML table, <code>kable_styling()</code> will automatically apply twitter bootstrap theme to the table. Now it should looks the same as the original pandoc output (the one when you don’t specify <code>format</code> in <code>kable()</code>) but this time, you are controlling it.</p>
+<p>When used on a HTML table, <code>kable_styling()</code> will automatically apply twitter bootstrap theme to the table. Now it should looks the same as the original pandoc output (the one when you don’t specify <code>format</code> in <code>kbl()</code>) but this time, you are controlling it.</p>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_styling()</code></pre>
<table class="table" style="margin-left: auto; margin-right: auto;">
<thead>
@@ -2061,7 +2061,7 @@
<h2>Alternative themes</h2>
<p><code>kableExtra</code> also offers a few in-house alternative HTML table themes other than the default bootstrap theme. Right now there are 6 of them: <code>kable_paper</code>, <code>kable_classic</code>, <code>kable_classic_2</code>, <code>kable_minimal</code>, <code>kable_material</code> and <code>kable_material_dark</code>. These functions are alternatives to <code>kable_styling</code>, which means that you can specify any additional formatting options in <code>kable_styling</code> in these functions too. The only difference is that <code>bootstrap_options</code> (as discussed in the next section) is replaced with <code>lightable_options</code> at the same location with only two choices <code>striped</code> and <code>hover</code> available.</p>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_paper("hover")</code></pre>
<table class=" lightable-paper lightable-hover" style="font-family: "Arial Narrow", arial, helvetica, sans-serif; margin-left: auto; margin-right: auto;">
<thead>
@@ -2207,7 +2207,7 @@
</tbody>
</table>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_classic()</code></pre>
<table class=" lightable-classic" style="font-family: "Arial Narrow", "Source Sans Pro", sans-serif; margin-left: auto; margin-right: auto;">
<thead>
@@ -2353,7 +2353,7 @@
</tbody>
</table>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_classic_2()</code></pre>
<table class=" lightable-classic-2" style="font-family: "Arial Narrow", "Source Sans Pro", sans-serif; margin-left: auto; margin-right: auto;">
<thead>
@@ -2499,9 +2499,9 @@
</tbody>
</table>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_minimal()</code></pre>
-<table class=" lightable-minimal" style="font-family: calibri, cambria, "Source Sans Pro", sans-serif; margin-left: auto; margin-right: auto;">
+<table class=" lightable-minimal" style="font-family: "Trebuchet MS", verdana, calibri, sans-serif; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;">
@@ -2645,7 +2645,7 @@
</tbody>
</table>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_material(c("striped", "hover"))</code></pre>
<table class=" lightable-material lightable-striped lightable-hover" style="font-family: "Source Sans Pro", helvetica, sans-serif; margin-left: auto; margin-right: auto;">
<thead>
@@ -2791,7 +2791,7 @@
</tbody>
</table>
<pre class="r"><code>dt %>%
- kable() %>%
+ kbl() %>%
kable_material_dark()</code></pre>
<table class=" lightable-material-dark" style="font-family: "Source Sans Pro", helvetica, sans-serif; margin-left: auto; margin-right: auto;">
<thead>
@@ -2945,7 +2945,7 @@
<h2>Bootstrap table classes</h2>
<p>If you are familiar with twitter bootstrap, you probably have already known its predefined classes, including <code>striped</code>, <code>bordered</code>, <code>hover</code>, <code>condensed</code> and <code>responsive</code>. If you are not familiar, no worries, you can take a look at their <a href="http://getbootstrap.com/css/#tables">documentation site</a> to get a sense of how they look like. All of these options are available here.</p>
<p>For example, to add striped lines (alternative row colors) to your table and you want to highlight the hovered row, you can simply type:</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling(bootstrap_options = c("striped", "hover"))</code></pre>
<table class="table table-striped table-hover" style="margin-left: auto; margin-right: auto;">
<thead>
@@ -3091,7 +3091,7 @@
</tbody>
</table>
<p>The option <code>condensed</code> can also be handy in many cases when you don’t want your table to be too large. It has slightly shorter row height.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))</code></pre>
<table class="table table-striped table-hover table-condensed" style="margin-left: auto; margin-right: auto;">
<thead>
@@ -3237,7 +3237,7 @@
</tbody>
</table>
<p>Tables with option <code>responsive</code> looks the same with others on a large screen. However, on a small screen like phone, they are horizontally scrollable. Please resize your window to see the result.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))</code></pre>
<table class="table table-striped table-hover table-condensed table-responsive" style="margin-left: auto; margin-right: auto;">
<thead>
@@ -3386,7 +3386,7 @@
<div id="full-width" class="section level2">
<h2>Full width?</h2>
<p>By default, a bootstrap table takes 100% of the width. It is supposed to use together with its grid system to scale the table properly. However, when you are writing a rmarkdown document, you probably don’t want to write your own css/or grid. For some small tables with only few columns, a page wide table looks awful. To make it easier, you can specify whether you want the table to have <code>full_width</code> or not in <code>kable_styling</code>. By default, <code>full_width</code> is set to be <code>TRUE</code> for HTML tables (note that for LaTeX, the default is <code>FALSE</code> since I don’t want to change the “common” looks unless you specified it.)</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_paper(bootstrap_options = "striped", full_width = F)</code></pre>
<table class=" lightable-paper" style="font-family: "Arial Narrow", arial, helvetica, sans-serif; width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
@@ -3535,7 +3535,7 @@
<div id="position" class="section level2">
<h2>Position</h2>
<p>Table Position only matters when the table doesn’t have <code>full_width</code>. You can choose to align the table to <code>center</code>, <code>left</code> or <code>right</code> side of the page</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "left")</code></pre>
<table class="table table-striped" style="width: auto !important; ">
<thead>
@@ -3681,7 +3681,7 @@
</tbody>
</table>
<p>Becides these three common options, you can also wrap text around the table using the <code>float-left</code> or <code>float-right</code> options.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "float_right")</code></pre>
<table class="table table-striped" style="width: auto !important; float: right; margin-left: 10px;">
<thead>
@@ -3831,7 +3831,7 @@
<div id="font-size" class="section level2">
<h2>Font size</h2>
<p>If one of your tables is huge and you want to use a smaller font size for that specific table, you can use the <code>font_size</code> option.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling(bootstrap_options = "striped", font_size = 7)</code></pre>
<table class="table table-striped" style="font-size: 7px; margin-left: auto; margin-right: auto;">
<thead>
@@ -3980,7 +3980,7 @@
<div id="fixed-table-header-row" class="section level2">
<h2>Fixed Table Header Row</h2>
<p>If you happened to have a very long table, you may consider to use this <code>fixed_header</code> option to fix the header row on top as your readers scroll. By default, the background is set to white. If you need a different color, you can set <code>fixed_header = list(enabled = T, background = "red")</code>.</p>
-<pre class="r"><code>kable(mtcars[1:10, 1:5]) %>%
+<pre class="r"><code>kbl(mtcars[1:10, 1:5]) %>%
kable_styling(fixed_thead = T)</code></pre>
<table class="table" style="margin-left: auto; margin-right: auto;">
<thead>
@@ -4224,7 +4224,7 @@
)
)
-kable(text_tbl) %>%
+kbl(text_tbl) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, border_right = T) %>%
column_spec(2, width = "30em", background = "yellow")</code></pre>
@@ -4270,7 +4270,7 @@
<p><strong>Key Update</strong>: I understand the need of doing conditional formatting and the previous solution <code>cell_spec</code> is relatively hard to use. Therefore in kableExtra 1.2, I improved the functionality of <code>column_spec</code> so it can take vectorized input for most of its arguments (except <code>width</code>, <code>border_left</code> and <code>border_right</code>). It is really easy right now to format a column based on other values.</p>
</blockquote>
<pre class="r"><code>mtcars[1:8, 1:8] %>%
- kable() %>%
+ kbl() %>%
kable_paper(full_width = F) %>%
column_spec(2, color = spec_color(mtcars$mpg[1:8]),
link = "https://haozhu233.github.io/kableExtra") %>%
@@ -4548,7 +4548,7 @@
<div id="row-spec" class="section level2">
<h2>Row spec</h2>
<p>Similar with <code>column_spec</code>, you can define specifications for rows. Currently, you can either bold or italicize an entire row. Note that, similar with other row-related functions in <code>kableExtra</code>, for the position of the target row, you don’t need to count in header rows or the group labeling rows.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
column_spec(5:7, bold = T) %>%
row_spec(3:5, bold = T, color = "white", background = "#D7261E")</code></pre>
@@ -4699,7 +4699,7 @@
<div id="header-rows" class="section level2">
<h2>Header Rows</h2>
<p>One special case of <code>row_spec</code> is that you can specify the format of the header row via <code>row_spec(row = 0, ...)</code>.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
row_spec(0, angle = -45)</code></pre>
<table class="table table-striped" style="width: auto !important; margin-left: auto; margin-right: auto;">
@@ -4867,7 +4867,7 @@
c("#666666", "#999999", "#BBBBBB")))
) %>%
select(car, mpg, cyl) %>%
- kable(format = "html", escape = F) %>%
+ kbl(format = "html", escape = F) %>%
kable_styling("striped", full_width = F)</code></pre>
<table class="table table-striped" style="width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
@@ -5010,7 +5010,7 @@
Species, color = "white", bold = T,
background = spec_color(1:10, end = 0.9, option = "A", direction = -1)
)) %>%
- kable(escape = F, align = "c") %>%
+ kbl(escape = F, align = "c") %>%
kable_styling(c("striped", "condensed"), full_width = F)</code></pre>
<table class="table table-striped table-condensed" style="width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
@@ -5254,7 +5254,7 @@
title = NULL, # title will add a Title Panel on top
position = popover_dt$position
))
-kable(popover_dt, escape = FALSE) %>%
+kbl(popover_dt, escape = FALSE) %>%
kable_styling("striped", full_width = FALSE)</code></pre>
<table class="table table-striped" style="width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
@@ -5323,21 +5323,21 @@
hp = color_bar("lightgreen")(hp)
) %>%
select(car, everything()) %>%
- kable(escape = F) %>%
+ kbl(escape = F) %>%
kable_styling("hover", full_width = F) %>%
column_spec(5, width = "3cm") %>%
add_header_above(c(" ", "Hello" = 2, "World" = 2))</code></pre>
<table class="table table-hover" style="width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
<tr>
-<th style="border-bottom:hidden" colspan="1">
+<th style="empty-cells: hide;border-bottom:hidden;" colspan="1">
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
Hello
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
World
</div>
@@ -5456,26 +5456,26 @@
<div id="add-header-rows-to-group-columns" class="section level2">
<h2>Add header rows to group columns</h2>
<p>Tables with multi-row headers can be very useful to demonstrate grouped data. To do that, you can pipe your kable object into <code>add_header_above()</code>. The header variable is supposed to be a named character with the names as new column names and values as column span. For your convenience, if column span equals to 1, you can ignore the <code>=1</code> part so the function below can be written as `add_header_above(c(" “,”Group 1" = 2, “Group 2” = 2, “Group 3” = 2)).</p>
-<pre class="r"><code>kable(dt) %>%
- kable_styling("striped") %>%
+<pre class="r"><code>kbl(dt) %>%
+ kable_classic() %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2))</code></pre>
-<table class="table table-striped" style="margin-left: auto; margin-right: auto;">
+<table class=" lightable-classic" style="font-family: "Arial Narrow", "Source Sans Pro", sans-serif; margin-left: auto; margin-right: auto;">
<thead>
<tr>
-<th style="border-bottom:hidden" colspan="1">
+<th style="empty-cells: hide;" colspan="1">
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Group 1
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Group 2
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Group 3
</div>
</th>
@@ -5622,51 +5622,51 @@
</tbody>
</table>
<p>In fact, if you want to add another row of header on top, please feel free to do so.</p>
-<pre class="r"><code>kable(dt) %>%
- kable_styling(c("striped", "bordered")) %>%
+<pre class="r"><code>kbl(dt) %>%
+ kable_paper() %>%
add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>%
add_header_above(c(" ", "Group 4" = 4, "Group 5" = 2)) %>%
add_header_above(c(" ", "Group 6" = 6))</code></pre>
-<table class="table table-striped table-bordered" style="margin-left: auto; margin-right: auto;">
+<table class=" lightable-paper" style="font-family: "Arial Narrow", arial, helvetica, sans-serif; margin-left: auto; margin-right: auto;">
<thead>
<tr>
-<th style="border-bottom:hidden" colspan="1">
+<th style="empty-cells: hide;" colspan="1">
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="6">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="6">
+<div style="border-bottom: 1px solid #00000020; padding-bottom: 5px; ">
Group 6
</div>
</th>
</tr>
<tr>
-<th style="border-bottom:hidden" colspan="1">
+<th style="empty-cells: hide;" colspan="1">
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="4">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="4">
+<div style="border-bottom: 1px solid #00000020; padding-bottom: 5px; ">
Group 4
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #00000020; padding-bottom: 5px; ">
Group 5
</div>
</th>
</tr>
<tr>
-<th style="border-bottom:hidden" colspan="1">
+<th style="empty-cells: hide;" colspan="1">
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #00000020; padding-bottom: 5px; ">
Group 1
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #00000020; padding-bottom: 5px; ">
Group 2
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
-<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
+<th style="padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; " colspan="2">
+<div style="border-bottom: 1px solid #00000020; padding-bottom: 5px; ">
Group 3
</div>
</th>
@@ -5816,7 +5816,7 @@
<div id="group-rows-via-labeling" class="section level2">
<h2>Group rows via labeling</h2>
<p>Sometimes we want a few rows of the table being grouped together. They might be items under the same topic (e.g., animals in one species) or just different data groups for a categorical variable (e.g., age < 40, age > 40). With the function <code>group_rows()</code>/<code>pack_rows()</code> in <code>kableExtra</code>, this kind of task can be completed in one line. Please see the example below. Note that when you count for the start/end rows of the group, you don’t need to count for the header rows nor other group label rows. You only need to think about the row numbers in the “original R dataframe”.</p>
-<pre class="r"><code>kable(mtcars[1:10, 1:6], caption = "Group Rows") %>%
+<pre class="r"><code>kbl(mtcars[1:10, 1:6], caption = "Group Rows") %>%
kable_styling("striped", full_width = F) %>%
pack_rows("Group 1", 4, 7) %>%
pack_rows("Group 2", 8, 10)</code></pre>
@@ -6093,11 +6093,11 @@
</table>
<p>Another way to use <code>pack_rows</code> is to provide an grouping index, similar with <code>add_header_above()</code>. This feature is only available in kableExtra > 0.5.2.</p>
<pre class="r"><code># Not evaluated. This example generates the same table as above.
-kable(mtcars[1:10, 1:6], caption = "Group Rows") %>%
+kbl(mtcars[1:10, 1:6], caption = "Group Rows") %>%
kable_styling("striped", full_width = F) %>%
pack_rows(index = c(" " = 3, "Group 1" = 4, "Group 2" = 3))</code></pre>
<p>For advanced users, you can even define your own css for the group labeling.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
pack_rows("Group 1", 3, 5, label_row_css = "background-color: #666; color: #fff;")</code></pre>
<table class="table table-striped" style="width: auto !important; margin-left: auto; margin-right: auto;">
@@ -6264,7 +6264,7 @@
<div id="row-indentation" class="section level2">
<h2>Row indentation</h2>
<p>Unlike <code>pack_rows()</code>, which will insert a labeling row, sometimes we want to list a few sub groups under a total one. In that case, <code>add_indent()</code> is probably more apporiate. For advanced users, you can even define your own css for the group labeling.</p>
-<pre class="r"><code>kable(dt) %>%
+<pre class="r"><code>kbl(dt) %>%
kable_styling("striped", full_width = F) %>%
add_indent(c(1, 3, 5))</code></pre>
<table class="table table-striped" style="width: auto !important; margin-left: auto; margin-right: auto;">
@@ -6418,7 +6418,7 @@
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
-kable(collapse_rows_dt, align = "c") %>%
+kbl(collapse_rows_dt, align = "c") %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T) %>%
collapse_rows(columns = 1:2, valign = "top")</code></pre>
@@ -6451,7 +6451,7 @@
1
</td>
<td style="text-align:center;">
-1
+0
</td>
</tr>
<tr>
@@ -6475,7 +6475,7 @@
4
</td>
<td style="text-align:center;">
-1
+0
</td>
</tr>
<tr>
@@ -6483,7 +6483,7 @@
5
</td>
<td style="text-align:center;">
-0
+1
</td>
</tr>
<tr>
@@ -6548,7 +6548,7 @@
12
</td>
<td style="text-align:center;">
-1
+0
</td>
</tr>
<tr>
@@ -6559,7 +6559,7 @@
13
</td>
<td style="text-align:center;">
-1
+0
</td>
</tr>
<tr>
@@ -6589,14 +6589,14 @@
</blockquote>
<p>Documentations for <code>add_footnote</code> can be found <a href="http://haozhu233.github.io/kableExtra/legacy_features#add_footnote">here</a>.</p>
<p>There are four notation systems in <code>footnote</code>, namely <code>general</code>, <code>number</code>, <code>alphabet</code> and <code>symbol</code>. The last three types of footnotes will be labeled with corresponding marks while <code>general</code> won’t be labeled. You can pick any one of these systems or choose to display them all for fulfill the APA table footnotes requirements.</p>
-<pre class="r"><code>kable(dt, align = "c") %>%
- kable_styling(full_width = F) %>%
+<pre class="r"><code>kbl(dt, align = "c") %>%
+ kable_classic(full_width = F) %>%
footnote(general = "Here is a general comments of the table. ",
number = c("Footnote 1; ", "Footnote 2; "),
alphabet = c("Footnote A; ", "Footnote B; "),
symbol = c("Footnote Symbol 1; ", "Footnote Symbol 2")
)</code></pre>
-<table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;">
+<table class=" lightable-classic" style="font-family: "Arial Narrow", "Source Sans Pro", sans-serif; width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;">
@@ -6782,7 +6782,7 @@
</tfoot>
</table>
<p>You can also specify title for each category by using the <code>***_title</code> arguments. Default value for <code>general_title</code> is “Note:” and "" for the rest three. You can also change the order using <code>footnote_order</code>. You can even display footnote as chunk texts (default is as a list) using <code>footnote_as_chunk</code>. The font format of the titles are controlled by <code>title_format</code> with options including “italic” (default), “bold” and “underline”.</p>
-<pre class="r"><code>kable(dt, align = "c") %>%
+<pre class="r"><code>kbl(dt, align = "c") %>%
kable_styling(full_width = F) %>%
footnote(general = "Here is a general comments of the table. ",
number = c("Footnote 1; ", "Footnote 2; "),
@@ -6960,12 +6960,10 @@
<p>If you need to add footnote marks in table, you need to do it manually (no fancy) using <code>footnote_mark_***()</code>. Remember that similar with <code>cell_spec</code>, you need to tell this function whether you want it to do it in <code>HTML</code> (default) or <code>LaTeX</code>. You can set it for all using the <code>knitr.table.format</code> global option. ALso, if you have ever use <code>footnote_mark_***()</code>, you need to put <code>escape = F</code> in your <code>kable</code> function to avoid escaping of special characters.</p>
<pre class="r"><code>dt_footnote <- dt
names(dt_footnote)[2] <- paste0(names(dt_footnote)[2],
- footnote_marker_symbol(1))</code></pre>
-<pre><code>## Setting footnote_marker_symbol format as html</code></pre>
-<pre class="r"><code>row.names(dt_footnote)[4] <- paste0(row.names(dt_footnote)[4],
- footnote_marker_alphabet(1))</code></pre>
-<pre><code>## Setting footnote_marker_alphabet format as html</code></pre>
-<pre class="r"><code>kable(dt_footnote, align = "c",
+ footnote_marker_symbol(1))
+row.names(dt_footnote)[4] <- paste0(row.names(dt_footnote)[4],
+ footnote_marker_alphabet(1))
+kbl(dt_footnote, align = "c",
# Remember this escape = F
escape = F) %>%
kable_styling(full_width = F) %>%
@@ -7135,7 +7133,7 @@
<h2>Scroll box</h2>
<p>If you have a huge table and you don’t want to reduce the font size to unreadable, you may want to put your HTML table in a scroll box, of which users can pick the part they like to read. Note that scroll box isn’t printer friendly, so be aware of that when you use this feature.</p>
<p>When you use <code>scroll_box</code>, you can specify either <code>height</code> or <code>width</code>. When you specify <code>height</code>, you will get a vertically scrollable box and vice versa. If you specify both, you will get a two-way scrollable box.</p>
-<pre class="r"><code>kable(cbind(mtcars, mtcars)) %>%
+<pre class="r"><code>kbl(cbind(mtcars, mtcars)) %>%
kable_styling() %>%
scroll_box(width = "500px", height = "200px")</code></pre>
<div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:200px; overflow-x: scroll; width:500px; ">
@@ -9490,7 +9488,7 @@
</div>
<p><br></p>
<p>You can also specify width using a percentage.</p>
-<pre class="r"><code>kable(cbind(mtcars, mtcars)) %>%
+<pre class="r"><code>kbl(cbind(mtcars, mtcars)) %>%
add_header_above(c("a" = 5, "b" = 18)) %>%
kable_styling() %>%
scroll_box(width = "100%", height = "200px")</code></pre>
@@ -9498,12 +9496,12 @@
<table class="table" style="margin-left: auto; margin-right: auto;">
<thead>
<tr>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; position: sticky; top:0; background-color: #FFFFFF;" colspan="5">
+<th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; position: sticky; top:0; background-color: #FFFFFF;" colspan="5">
<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
a
</div>
</th>
-<th style="border-bottom:hidden; padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; position: sticky; top:0; background-color: #FFFFFF;" colspan="18">
+<th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; position: sticky; top:0; background-color: #FFFFFF;" colspan="18">
<div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">
b
</div>
@@ -11861,7 +11859,7 @@
<div id="save-html-table-directly" class="section level2">
<h2>Save HTML table directly</h2>
<p>If you need to save those HTML tables but you don’t want to generate them through rmarkdown, you can try to use the <code>save_kable()</code> function. You can choose whether to let those HTML files be self contained (default is yes). Self contained files packed CSS into the HTML file so they are quite large when there are many.</p>
-<pre class="r"><code>kable(mtcars) %>%
+<pre class="r"><code>kbl(mtcars) %>%
kable_styling() %>%
save_kable(file = "table1.html", self_contained = T)</code></pre>
</div>
diff --git a/docs/awesome_table_in_pdf.Rmd b/docs/awesome_table_in_pdf.Rmd
index 7959839..6469847 100644
--- a/docs/awesome_table_in_pdf.Rmd
+++ b/docs/awesome_table_in_pdf.Rmd
@@ -58,12 +58,10 @@
dt <- mtcars[1:5, 1:6]
```
-When you are using `kable()`, if you don't specify `format`, by default it will generate a markdown table and let pandoc handle the conversion from markdown to HTML/PDF. This is the most favorable approach to render most simple tables as it is format independent. If you switch from HTML to pdf, you basically don't need to change anything in your code. However, markdown doesn't support complex table. For example, if you want to have a double-row header table, markdown just cannot provide you the functionality you need. As a result, when you have such a need, you should **define `format` in `kable()`** as either "html" or "latex". *You can also define a global option at the beginning using `options(knitr.table.format = "latex")` so you don't repeat the step every time.* **In this tutorial, I’ll still put format="latex" in the function in
-case users just want to quickly replicate the results. In practice, you don't need to define those formats.**
+> **Key Update:** In the latest version of this package (1.2+), we provide a wrapper funciton `kbl` to the original `kable` function with detailed documentation of all the hidden html/latex options. It also does auto-formatting check in every function call instead of relying on the global environement variable. As a result, it also solves an issue for multi-format R Markdown documents. I encourage you start to use the new `kbl` function for all its convenience but the support for the original `kable` function is still there. In this doc, we will use `kbl` instead of `kable`.
-**Starting from `kableExtra` 0.9.0**, when you load this package (`library(kableExtra)`), `r text_spec("it will automatically set up the global option 'knitr.table.format' based on your current environment", bold = T, color = "red")`. Unless you are rendering a PDF, `kableExtra` will try to render a HTML table for you. **You no longer need to manually set either the global option or the `format` option in each `kable()` function**. I'm still including the explanation above here in this vignette so you can understand what is going on behind the scene. Note that this is only an global option. You can manually set any format in `kable()` whenever you want. I just hope you can enjoy a peace of mind in most of your time.
-You can disable this behavior by setting `options(kableExtra.auto_format = FALSE)` before you load `kableExtra`.
+**This paragraph is a little outdated. It's here only for education purpose because it's helpful to understand how `kable` works under the hood**. When you are using `kable()`, if you don't specify `format`, by default it will generate a markdown table and let pandoc handle the conversion from markdown to HTML/PDF. This is the most favorable approach to render most simple tables as it is format independent. If you switch from HTML to pdf, you basically don't need to change anything in your code. However, markdown doesn't support complex table. For example, if you want to have a double-row header table, markdown just cannot provide you the functionality you need. As a result, when you have such a need, you should **define `format` in `kable()`** as either "html" or "latex". *You can also define a global option at the beginning using `options(knitr.table.format = "html")` so you don't repeat the step everytime.* **Starting from `kableExtra` 0.9.0**, when you load this package (`library(kableExtra)`), it will automatically set up the global option 'knitr.table.format' based on your current environment. Unless you are rendering a PDF, `kableExtra` will try to render a HTML table for you. **You no longer need to manually set either the global option or the `format` option in each `kable()` function**. I'm still including the explanation above here in this vignette so you can understand what is going on behind the scene. Note that this is only an global option. You can manually set any format in `kable()` whenever you want. I just hope you can enjoy a peace of mind in most of your time. You can disable this behavior by setting `options(kableExtra.auto_format = FALSE)` before you load `kableExtra`.
```{r}
# If you are using kableExtra < 0.9.0, you are recommended to set a global option first.
@@ -107,7 +105,7 @@
```{r}
# Again, with kableExtra >= 0.9.0, `format = "latex"` is automatically defined
# when this package gets loaded. Otherwise, you still need to define formats
-kable(dt, "latex")
+kbl(dt)
# Same: kable(dt, "latex")
```
@@ -115,7 +113,7 @@
Similar to Bootstrap in HTML, in LaTeX, you can also use a trick to make your table look prettier as well. The different part is that, this time you don't need to pipe kable outputs to another function. Instead, you should call `booktabs = T` directly in `kable()`.
```{r}
-kable(dt, "latex", booktabs = T)
+kbl(dt, booktabs = T)
```
# Table Styles
@@ -127,21 +125,21 @@
### Striped
Even though in the LaTeX world, people usually call it `alternative row colors` but here I'm using its bootstrap name for consistency. Note that to make it happen, LaTeX package `xcolor` is required to be loaded. In an environment like rmarkdown::pdf_document (rmarkdown 1.4.0 +), `kable_styling` will load it automatically if `striped` is enabled. However, in other cases, you probably need to import that package by yourself.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kbl(dt, booktabs = T) %>%
kable_styling(latex_options = "striped")
```
You can also specify which rows you want to striped on via `stripe_index`. In most case, you might want to turn off the default 5 rows + a space setting in `knitr::kable()` by setting `linesep = ""`. See this SO answer for details. https://stackoverflow.com/questions/45409750/get-rid-of-addlinespace-in-kable.
```{r}
-kable(mtcars[1:8, 1:4], "latex", booktabs = T, linesep = "") %>%
+kbl(mtcars[1:8, 1:4], booktabs = T, linesep = "") %>%
kable_styling(latex_options = "striped", stripe_index = c(1,2, 5:6))
```
### Hold position
-If you provide a table caption in `kable()`, it will put your LaTeX tabular in a `table` environment, unless you are using `longtable`. A `table` environment will automatically find the best place (it thinks) to put your table. However, in many cases, you do want your table to appear in a position you want it to be. In this case, you can use this `hold_position` options here.
+If you provide a table caption in `kbl()`, it will put your LaTeX tabular in a `table` environment, unless you are using `longtable`. A `table` environment will automatically find the best place (it thinks) to put your table. However, in many cases, you do want your table to appear in a position you want it to be. In this case, you can use this `hold_position` options here.
```{r}
-kable(dt, "latex", caption = "Demo table", booktabs = T) %>%
+kbl(dt, caption = "Demo table", booktabs = T) %>%
kable_styling(latex_options = c("striped", "hold_position"))
```
@@ -150,11 +148,11 @@
### Scale down
When you have a wide table that will normally go out of the page, and you want to scale down the table to fit the page, you can use the `scale_down` option here. Note that, if your table is too small, it will also scale up your table. It was named in this way only because scaling up isn't very useful in most cases. You should also note that `scale_down` does not work with `longtable`. If you `longtable` is too wide, you should manually adjust your fontsize or switch to landscape layout.
```{r}
-kable(cbind(dt, dt, dt), "latex", booktabs = T) %>%
+kbl(cbind(dt, dt, dt), booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down"))
```
```{r}
-kable(cbind(dt), "latex", booktabs = T) %>%
+kbl(cbind(dt), booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down"))
```
@@ -163,7 +161,7 @@
```{r}
long_dt <- rbind(mtcars, mtcars)
-kable(long_dt, "latex", longtable = T, booktabs = T, caption = "Longtable") %>%
+kbl(long_dt, longtable = T, booktabs = T, caption = "Longtable") %>%
add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6)) %>%
kable_styling(latex_options = c("repeat_header"))
```
@@ -172,7 +170,7 @@
## Full width?
If you have a small table and you want it to spread wide on the page, you can try the `full_width` option. Unlike `scale_down`, it won't change your font size. You can use `column_spec`, which will be explained later, together with `full_width` to achieve the best result.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling(full_width = T) %>%
column_spec(1, width = "8cm")
```
@@ -182,13 +180,13 @@
Note that even though you can select to `right` align your table but the table will actually be centered. Somehow it is very difficult to right align a table in LaTeX (since it's not very useful in the real world?). If you know how to do it, please send out an issue or PR and let me know.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling(position = "center")
```
Besides these three common options, you can also wrap text around the table using the `float-left` or `float-right` options. Note that, like `striped`, this feature will load another non-default LaTeX package `wrapfig` which requires rmarkdown 1.4.0 +. If you rmarkdown version < 1.4.0, you need to load the package through a customed LaTeX template file.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling(position = "float_right")
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet mauris in ex ultricies elementum vel rutrum dolor. Phasellus tempor convallis dui, in hendrerit mauris placerat scelerisque. Maecenas a accumsan enim, a maximus velit. Pellentesque in risus eget est faucibus convallis nec at nulla. Phasellus nec lacinia justo. Morbi fermentum, orci id varius accumsan, nibh neque porttitor ipsum, consectetur luctus risus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam non vulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sed congue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Nam accumsan urna risus, non feugiat odio vehicula eget.
@@ -196,7 +194,7 @@
## Font Size
If one of your tables is huge and you want to use a smaller font size for that specific table, you can use the `font_size` option.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling(font_size = 7)
```
@@ -213,7 +211,7 @@
)
)
-kable(text_tbl, "latex", booktabs = T) %>%
+kable(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
@@ -243,7 +241,7 @@
Similar with `column_spec`, you can define specifications for rows. Currently, you can either bold or italicize an entire row. Note that, similar to other row-related functions in `kableExtra`, for the position of the target row, you don't need to count in header rows or the group labeling rows.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling("striped", full_width = F) %>%
column_spec(7, border_left = T, bold = T) %>%
row_spec(1, strikeout = T) %>%
@@ -253,7 +251,7 @@
## Header Rows
One special case of `row_spec` is that you can specify the format of the header row via `row_spec(row = 0, ...)`.
```{r}
-kable(dt, "latex", booktabs = T, align = "c") %>%
+kable(dt, booktabs = T, align = "c") %>%
kable_styling(latex_options = "striped", full_width = F) %>%
row_spec(0, angle = 45)
```
@@ -278,8 +276,8 @@
mutate(
car = row.names(.),
# You don't need format = "latex" if you have ever defined options(knitr.table.format)
- mpg = cell_spec(mpg, "latex", color = ifelse(mpg > 20, "red", "blue")),
- cyl = cell_spec(cyl, "latex", color = "white", align = "c", angle = 45,
+ mpg = cell_spec(mpg, color = ifelse(mpg > 20, "red", "blue")),
+ cyl = cell_spec(cyl, color = "white", align = "c", angle = 45,
background = factor(cyl, c(4, 6, 8),
c("#666666", "#999999", "#BBBBBB")))
) %>%
@@ -293,11 +291,11 @@
```{r}
iris[1:10, ] %>%
mutate_if(is.numeric, function(x) {
- cell_spec(x, "latex", bold = T, color = spec_color(x, end = 0.9),
+ cell_spec(x, bold = T, color = spec_color(x, end = 0.9),
font_size = spec_font_size(x))
}) %>%
mutate(Species = cell_spec(
- Species, "latex", color = "white", bold = T,
+ Species, color = "white", bold = T,
background = spec_color(1:10, end = 0.9, option = "A", direction = -1)
)) %>%
kable("latex", escape = F, booktabs = T, linesep = "", align = "c")
@@ -317,7 +315,7 @@
"and nobody can resist. ;)"
), " ")[[1]]
text_formatted <- paste(
- text_spec(sometext, "latex", color = spec_color(1:length(sometext), end = 0.9),
+ text_spec(sometext, color = spec_color(1:length(sometext), end = 0.9),
font_size = spec_font_size(1:length(sometext), begin = 5, end = 20)),
collapse = " ")
@@ -329,14 +327,14 @@
## Add header rows to group columns
Tables with multi-row headers can be very useful to demonstrate grouped data. To do that, you can pipe your kable object into `add_header_above()`. The header variable is supposed to be a named character with the names as new column names and values as column span. For your convenience, if column span equals to 1, you can ignore the `=1` part so the function below can be written as `add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)).
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling() %>%
add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2))
```
In fact, if you want to add another row of header on top, please feel free to do so. Also, since kableExtra 0.3.0, you can specify `bold` & `italic` as you do in `row_spec()`.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
kable_styling(latex_options = "striped") %>%
add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>%
add_header_above(c(" ", "Group 4" = 4, "Group 5" = 2)) %>%
@@ -346,7 +344,7 @@
## Group rows via labeling
Sometimes we want a few rows of the table being grouped together. They might be items under the same topic (e.g., animals in one species) or just different data groups for a categorical variable (e.g., age < 40, age > 40). With the function `pack_rows`/`group_rows()` in `kableExtra`, this kind of task can be completed in one line. Please see the example below. Note that when you count for the start/end rows of the group, you don't need to count for the header rows nor other group label rows. You only need to think about the row numbers in the "original R dataframe".
```{r}
-kable(mtcars[1:10, 1:6], "latex", caption = "Group Rows", booktabs = T) %>%
+kable(mtcars[1:10, 1:6], caption = "Group Rows", booktabs = T) %>%
kable_styling() %>%
pack_rows("Group 1", 4, 7) %>%
pack_rows("Group 2", 8, 10)
@@ -354,13 +352,13 @@
In case some users need it, you can define your own gapping spaces between the group labeling row and previous rows. The default value is `0.5em`.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
pack_rows("Group 1", 4, 5, latex_gap_space = "2em")
```
If you prefer to build multiple groups in one step, you can use the short-hand `index` option. Basically, you can use it in the same way as you use `add_header_above`. However, since `group_row` only support one layer of grouping, you can't add multiple layers of grouping header as you can do in `add_header_above`.
```{r, eval=FALSE}
-kable(mtcars[1:10, 1:6], "latex", caption = "Group Rows", booktabs = T) %>%
+kable(mtcars[1:10, 1:6], caption = "Group Rows", booktabs = T) %>%
kable_styling() %>%
pack_rows(index=c(" " = 3, "Group 1" = 4, "Group 2" = 3))
# Not evaluated. The code above should have the same result as the first example in this section.
@@ -372,7 +370,7 @@
For example,
```{r, eval=F}
-kable(mtcars[1:2, 1:2], "latex", align = c("cl"))
+kable(mtcars[1:2, 1:2], align = c("cl"))
# \begin{tabular}{l|cl|cl} # Note the column alignment here
# \hline
# & mpg & cyl\\
@@ -385,14 +383,14 @@
Unlike `pack_rows()`, which will insert a labeling row, sometimes we want to list a few sub groups under a total one. In that case, `add_indent()` is probably more appropriate.
```{r}
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
add_indent(c(1, 3, 5))
```
You can also specify the width of the indentation by the `level_of_indent` option. At the same time, if you want to indent every column, you can choose to turn on `all_cols`. Note that if a column is right aligned, you probably won't be able to see the effect.
```{r}
-kable(dt, "latex", booktabs = T, align = "l") %>%
+kable(dt, booktabs = T, align = "l") %>%
add_indent(c(1, 3, 5), level_of_indent = 2, all_cols = T)
```
@@ -406,14 +404,14 @@
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
-kable(collapse_rows_dt, "latex", booktabs = T, align = "c") %>%
+kable(collapse_rows_dt, booktabs = T, align = "c") %>%
column_spec(1, bold=T) %>%
collapse_rows(columns = 1:2, latex_hline = "major", valign = "middle")
```
Right now, you can't automatically make striped rows based on collapsed rows but you can do it manually via the `extra_latex_after` option in `row_spec`. This feature is not officially supported. I'm only document it here if you want to give it a try.
```{r}
-kable(collapse_rows_dt[-1], "latex", align = "c", booktabs = T) %>%
+kable(collapse_rows_dt[-1], align = "c", booktabs = T) %>%
column_spec(1, bold = T, width = "5em") %>%
row_spec(c(1:7, 11:12) - 1, extra_latex_after = "\\rowcolor{gray!6}") %>%
collapse_rows(1, latex_hline = "none")
@@ -433,7 +431,7 @@
mutate(C1 = rnorm(n()),
C2 = rnorm(n()))
-kable(collapse_rows_dt, "latex",
+kable(collapse_rows_dt,
booktabs = T, align = "c", linesep = '') %>%
collapse_rows(1:3, row_group_label_position = 'stack')
```
@@ -445,7 +443,7 @@
list(bold = T, italic = T),
list(bold = F, italic = F)
)
-kable(collapse_rows_dt, "latex",
+kable(collapse_rows_dt,
booktabs = T, align = "c", linesep = '') %>%
column_spec(1, bold=T) %>%
collapse_rows(1:3, latex_hline = 'custom', custom_latex_hline = 1:3,
@@ -461,7 +459,7 @@
There are four notation systems in `footnote`, namely `general`, `number`, `alphabet` and `symbol`. The last three types of footnotes will be labeled with corresponding marks while `general` won't be labeled. You can pick any one of these systems or choose to display them all for fulfilling the APA table footnotes requirements.
```{r}
-kable(dt, "latex", align = "c") %>%
+kable(dt, align = "c") %>%
kable_styling(full_width = F) %>%
footnote(general = "Here is a general comments of the table. ",
number = c("Footnote 1; ", "Footnote 2; "),
@@ -473,7 +471,7 @@
You can also specify title for each category by using the `***_title` arguments. Default value for `general_title` is "Note: " and "" for the rest three. You can also change the order using `footnote_order`. You can even display footnote as chunk texts (default is as a list) using `footnote_as_chunk`. The font format of the titles are controlled by `title_format` with options including "italic" (default), "bold" and "underline".
```{r}
-kable(dt, "latex", align = "c", booktabs = T) %>%
+kable(dt, align = "c", booktabs = T) %>%
footnote(general = "Here is a general comments of the table. ",
number = c("Footnote 1; ", "Footnote 2; "),
alphabet = c("Footnote A; ", "Footnote B; "),
@@ -493,7 +491,7 @@
footnote_marker_symbol(1, "latex"))
row.names(dt_footnote)[4] <- paste0(row.names(dt_footnote)[4],
footnote_marker_alphabet(1))
-kable(dt_footnote, "latex", align = "c", booktabs = T,
+kable(dt_footnote, align = "c", booktabs = T,
# Remember this escape = F
escape = F) %>%
footnote(alphabet = "Footnote A; ",
@@ -505,7 +503,7 @@
If your table footnote is very long, please consider to put your table in a `ThreePartTable` frame. Note that, in kableExtra version <= 0.7.0, we were using `threeparttable` but since kableExtra 0.8.0, we start to use `ThreePartTable` from `threeparttablex` instead. `ThreePartTable` supports both the `longtable` and `tabu` environments.
```{r}
-kable(dt, "latex", align = "c", booktabs = T, caption = "s") %>%
+kable(dt, align = "c", booktabs = T, caption = "s") %>%
footnote(general = "Here is a very very very very very very very very very very very very very very very very very very very very long footnote",
threeparttable = T)
```
@@ -532,7 +530,7 @@
## Table on a Landscape Page
Sometimes when we have a wide table, we want it to sit on a designated landscape page. The new function `landscape()` can help you on that. Unlike other functions, this little function only serves LaTeX and doesn't have a HTML side.
```{r}
-kable(dt, "latex", caption = "Demo Table (Landscape)[note]", booktabs = T) %>%
+kable(dt, caption = "Demo Table (Landscape)[note]", booktabs = T) %>%
kable_styling(latex_options = c("hold_position")) %>%
add_header_above(c(" ", "Group 1[note]" = 3, "Group 2[note]" = 3)) %>%
add_footnote(c("This table is from mtcars",
@@ -544,20 +542,20 @@
```
## Use LaTeX table in HTML or Word
-If you want to include a LaTeX rendered table in your HTML or Word document, or if you just want to save table as an image, you may consider using `kable_as_image()`. Note that this feature requires you to have [magick](https://github.com/ropensci/magick) installed (`install.packages("magick")`). Also, if you are planning to use it on Windows, you need to install [Ghostscript](https://www.ghostscript.com/). This feature may not work if you are using tinytex. If you are using tinytex, please consider using other alternatives to this function.
+If you want to save a LaTeX table to a image, you may consider using `save_kable()`. We also provide an `as_image()` function as a convenience wrapper for `save_kable()`. It will save the image to a temp location. Note that this feature requires you to have [magick](https://github.com/ropensci/magick) installed (`install.packages("magick")`). Also, if you are planning to use it on Windows, you need to install [Ghostscript](https://www.ghostscript.com/). This feature may not work if you are using tinytex. If you are using tinytex, please consider using other alternatives to this function.
```{r, eval = F}
# Not evaluated.
# The code below will automatically include the image in the rmarkdown document
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
column_spec(1, bold = T) %>%
- kable_as_image()
+ as_image()
# If you want to save the image locally, just provide a name
-kable(dt, "latex", booktabs = T) %>%
+kable(dt, booktabs = T) %>%
column_spec(1, bold = T) %>%
- kable_as_image("my_latex_table")
+ save_kable("my_latex_table.png")
```
# From other packages
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index 10b350d..de42e9f 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ
diff --git a/docs/awesome_table_in_pdf.toc b/docs/awesome_table_in_pdf.toc
index 984d331..dd2e50b 100644
--- a/docs/awesome_table_in_pdf.toc
+++ b/docs/awesome_table_in_pdf.toc
@@ -27,8 +27,8 @@
\contentsline {subsection}{Row indentation}{15}{section*.28}%
\contentsline {subsection}{Group rows via multi-row cell}{16}{section*.29}%
\contentsline {section}{Table Footnote}{19}{section*.30}%
-\contentsline {section}{LaTeX Only Features}{22}{section*.31}%
-\contentsline {subsection}{Linebreak processor}{22}{section*.32}%
+\contentsline {section}{LaTeX Only Features}{21}{section*.31}%
+\contentsline {subsection}{Linebreak processor}{21}{section*.32}%
\contentsline {subsection}{Table on a Landscape Page}{22}{section*.33}%
\contentsline {subsection}{Use LaTeX table in HTML or Word}{24}{section*.34}%
\contentsline {section}{From other packages}{24}{section*.35}%