update documentation
diff --git a/NAMESPACE b/NAMESPACE
index 0b5eea7..db4b355 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -12,7 +12,6 @@
export(kable_as_image)
export(kable_styling)
export(landscape)
-export(latex_pkg_list)
export(magic_mirror)
export(rmd_format)
export(row_spec)
@@ -20,6 +19,7 @@
export(spec_angle)
export(spec_color)
export(spec_font_size)
+export(text_spec)
export(usepackage_latex)
importFrom(knitr,include_graphics)
importFrom(knitr,knit_meta_add)
@@ -30,6 +30,7 @@
importFrom(rmarkdown,metadata)
importFrom(rvest,html_table)
importFrom(scales,rescale)
+importFrom(stats,ave)
importFrom(stringr,str_count)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
diff --git a/R/cell_spec.R b/R/cell_spec.R
index 0f55d31..4fa5895 100644
--- a/R/cell_spec.R
+++ b/R/cell_spec.R
@@ -1,37 +1,41 @@
-#' Specify Cell format
+#' Specify Cell/Text format
#'
#' @description Specify Cell format before it gets into kable
#'
#' @param x Things to be formated. It could be a vector of numbers or strings.
#' @param format Either "html" or "latex". It can also be set through
#' `option(knitr.table.format)`, same as `knitr::kable()`.
-#' @param bold A T/F value to control whether the text of the selected column
-#' need to be bolded.
-#' @param italic A T/F value to control whether the text of the selected column
-#' need to be emphasized.
-#' @param monospace A T/F value to control whether the text of the selected column
-#' need to be monospaced (verbatim)
-#' @param color A character string for column text color. Here please pay
+#' @param bold T/F for font bold.
+#' @param italic T/F for font italic.
+#' @param monospace T/F for font monospaced (verbatim)
+#' @param color A character string for text color. Here please pay
#' attention to the differences in color codes between HTML and LaTeX.
-#' @param background A character string for column background color. Here please
-#' pay attention to the differences in color codes between HTML and LaTeX.
-#' @param align A character string for cell alignment. For HTML, possible values could
-#' be `l`, `c`, `r` plus `left`, `center`, `right`, `justify`, `initial` and `inherit`
-#' while for LaTeX, you can only choose from `l`, `c` & `r`.
-#' @param font_size Only if you want to specify font size locally in HTML.
-#' This feature is not available in LaTeX
+#' @param background A character string for background color. Here please
+#' pay attention to the differences in color codes between HTML and LaTeX. Also
+#' note that in HTML, background defined in cell_spec won't cover the whole
+#' cell.
+#' @param align A character string for cell alignment. For HTML, possible
+#' values could be `l`, `c`, `r` plus `left`, `center`, `right`, `justify`,
+#' `initial` and `inherit` while for LaTeX, you can only choose
+#' from `l`, `c` & `r`.
+#' @param font_size j
#' @param angle 0-360, degree that the text will rotate. Can be a vector.
#' @param tooltip A vector of strings to be displayed as tooltip.
-#' Of course, this feature is only available in HTML.
+#' Obviously, this feature is only available in HTML.
#' @param background_as_tile T/F value indicating if you want to have round
-#' cornered tile as background.
+#' cornered tile as background in HTML.
+#' @param latex_background_in_cell T/F value. It only takes effect in LaTeX
+#' when `background` provided, Default value is `TRUE`. If it's `TRUE`, the
+#' background only works in a table cell. If it's `FALSE`, it works outside of a
+#' table environment.
#'
#' @export
cell_spec <- function(x, format,
bold = F, italic = F, monospace = F,
color = NULL, background = NULL,
align = NULL, font_size = NULL, angle = NULL,
- tooltip = NULL, background_as_tile = TRUE) {
+ tooltip = NULL, background_as_tile = TRUE,
+ latex_background_in_cell = TRUE) {
if (missing(format) || is.null(format)) format = getOption('knitr.table.format')
if (is.null(format)) {
@@ -46,7 +50,8 @@
}
if (tolower(format) == "latex") {
return(cell_spec_latex(x, bold, italic, monospace,
- color, background, align, angle))
+ color, background, align, font_size, angle,
+ latex_background_in_cell))
}
}
@@ -72,32 +77,34 @@
cell_style <- paste0(cell_style, "text-align: ", align, ";")
}
if (!is.null(font_size)) {
- cell_style <- paste0(cell_style, "font-size: ", font_size, "px;")
+ if (is.numeric) font_size <- paste0(font_size, "px")
+ cell_style <- paste0(cell_style, "font-size: ", font_size, ";")
}
- if (!is.null(angle)) {
- cell_style <- paste0(cell_style,
- "-webkit-transform: rotate(", angle,
- "deg); -moz-transform: rotate(", angle,
- "deg); -ms-transform: rotate(", angle,
- "deg); -o-transform: rotate(", angle,
- "deg); transform: rotate(", angle,
- "deg);")
- }
-
if (!is.null(tooltip)) {
tooltip <- gsub("\n", "
", tooltip)
tooltip <- paste0("data-toggle='tooltip' title='", tooltip, "'")
}
out <- paste0(
- '<div style="', cell_style, '"', tooltip, '>', x, '</div>'
+ '<span style="', cell_style, '"', tooltip, '>', x, '</span>'
)
+
+ if (!is.null(angle)) {
+ rotate_css <- paste0("-webkit-transform: rotate(", angle,
+ "deg); -moz-transform: rotate(", angle,
+ "deg); -ms-transform: rotate(", angle,
+ "deg); -o-transform: rotate(", angle,
+ "deg); transform: rotate(", angle,
+ "deg);")
+ out <- paste0('<div style="', rotate_css, '">', out, '</div>')
+ }
return(out)
}
cell_spec_latex <- function(x, bold, italic, monospace,
- color, background, align, angle) {
+ color, background, align, font_size, angle,
+ latex_background_in_cell) {
if (bold) x <- paste0("\\bfseries{", x, "}")
- if (italic) x <-paste0("\\em{", x, "}")
+ if (italic) x <- paste0("\\em{", x, "}")
if (monospace) x <- paste0("\\ttfamily{", x, "}")
if (!is.null(color)) {
color <- latex_color(color)
@@ -105,9 +112,27 @@
}
if (!is.null(background)) {
background <- latex_color(background)
- x <- paste0("\\cellcolor", background, "{", x, "}")
+ background_env <- ifelse(latex_background_in_cell, "cellcolor", "colorbox")
+ x <- paste0("\\", background_env, background, "{", x, "}")
}
- if (!is.null(align)) x <- paste0("\\multicolumn{1}{", align, "}{", x, "}")
+ if (!is.null(font_size)) {
+ x <- paste0("\\begingroup\\fontsize{", font_size, "}{", as.numeric(font_size) + 2,
+ "}\\selectfont ", x, "\\endgroup")
+ }
if (!is.null(angle)) x <- paste0("\\rotatebox{", angle, "}{", x, "}")
+ if (!is.null(align)) x <- paste0("\\multicolumn{1}{", align, "}{", x, "}")
return(x)
}
+
+#' @rdname cell_spec
+#' @export
+text_spec <- function(x, format,
+ bold = F, italic = F, monospace = F,
+ color = NULL, background = NULL,
+ align = NULL, font_size = NULL, angle = NULL,
+ tooltip = NULL, background_as_tile = TRUE,
+ latex_background_in_cell = FALSE) {
+ cell_spec(x, format, bold, italic, monospace, color, background, align,
+ font_size, angle, tooltip, background_as_tile,
+ latex_background_in_cell)
+}
diff --git a/R/spec_tools.R b/R/spec_tools.R
index 03b2539..f8545d4 100644
--- a/R/spec_tools.R
+++ b/R/spec_tools.R
@@ -44,7 +44,7 @@
#' @param end Largest font size. Default is 20.
#' @param na_font_size font size for NA values
#' @export
-spec_font_size <- function(x, begin = 10, end = 20, na_font_size = "inherit") {
+spec_font_size <- function(x, begin = 8, end = 16, na_font_size = 12) {
x <- round(rescale(x, c(begin, end)))
x[is.na(x)] <- na_font_size
return(x)
diff --git a/docs/awesome_table_in_pdf.Rmd b/docs/awesome_table_in_pdf.Rmd
index 2d37e1b..aa7888c 100644
--- a/docs/awesome_table_in_pdf.Rmd
+++ b/docs/awesome_table_in_pdf.Rmd
@@ -65,9 +65,9 @@
library(kableExtra)
```
-If you are using R Sweave, beamer, tufte or some customized rmarkdown templates, you can put the following meta data into the `yaml` section. If you are familar with LaTeX and you know what you are doing, feel free to remove unnecessary packages from the list.
+If you are using R Sweave, beamer, R package vignette template, tufte or some customized rmarkdown templates, you can put the following meta data into the `yaml` section. If you are familar with LaTeX and you know what you are doing, feel free to remove unnecessary packages from the list.
-```{yaml}
+```
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
@@ -198,6 +198,67 @@
row_spec(3:5, bold = T, color = "white", background = "black")
```
+# Cell/Text Specification
+Function `cell_spec` is introduced in version 0.6.0 of `kableExtra`. Unlike `column_spec` and `row_spec`, **this function is designed to be used before the data.frame gets into the `kable` function**. Comparing with figuring out a list of 2 dimentional index for targeted cells, this design is way easier to learn and use and it fits perfectly well with `dplyr`'s `mutate` and `summarize` functions. With this design, there are two things to be noted:
+* Since `cell_spec` generates raw `HTML` or `LaTeX` code, make sure you remember to put `escape = FALSE` in `kable`. At the same time, you have to escape special symbols including `%` manually by yourself
+* `cell_spec` needs a way to know whether you want `html` or `latex`. You can specify it locally in function or globally via the `options(knitr.table.format = "latex")` method as suggested at the beginning. If you don't provide anything, this function will output as HTML by default.
+
+Currently, `cell_spec` supports features including bold, italic, monospace, text color, background color, align, font size & rotation angle. More features may be added in the future. Please see function documentations as reference.
+
+## Conditional logic
+It is very easy to use `cell_spec` with conditional logic. Here is an example.
+```{r}
+suppressMessages(library(dplyr))
+mtcars[1:10, 1:2] %>%
+ mutate(
+ # Since we are using tibble, we need to get the rownames
+ car = row.names(.),
+ # You don't need "latex" if you have ever defined options(knitr.table.format)
+ mpg = cell_spec(mpg, "latex", color = ifelse(mpg > 20, "green", "red")),
+ cyl = cell_spec(cyl, "latex", color = "white", align = "c", angle = 90,
+ background = factor(cyl, c(4, 6, 8),
+ c("#666666", "#999999", "#BBBBBB")))
+ ) %>%
+ select(car, mpg, cyl) %>%
+ kable("latex", escape = F, booktabs = T, linesep = "")
+```
+
+## Visualize data with Viridis Color
+This package also comes with a few helper functions, including `spec_color`, `spec_font_size` & `spec_angle`. These functions can rescale continuous variables to certain scales. For example, function `spec_color` would map a continuous variable to any [viridis color palettes](https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html). It offers a very visually impactful representation in a tabular format.
+
+```{r}
+iris[1:10, ] %>%
+ mutate_if(is.numeric, function(x) {
+ cell_spec(x, bold = T, color = spec_color(x, end = 0.9),
+ font_size = spec_font_size(x))
+ }) %>%
+ mutate(Species = cell_spec(
+ 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")
+```
+
+In the example above, I'm using the `mutate` functions from `dplyr`. You don't have to use it. Base R solutions like `iris$Species <- cell_spec(iris$Species, color = "red")` also works.
+
+## Text Specification
+If you check the results of `cell_spec`, you will find that this function does nothing more than wrapping the text with appropriate HTML/LaTeX formatting syntax. The result of this function is just a vector of character strings. As a result, when you are writing a `rmarkdown` document or write some text in shiny apps, if you need extra markups other than **bold** or *italic*, you may use this function to `r text_spec("color", color = "red")`, `r text_spec("change font size ", font_size = 16)` or `r text_spec("rotate", angle = 30)` your text.
+
+An alias function `text_spec` is also provided for a more literal writing experience. The only difference is that in LaTeX, unless you specify `latex_background_in_cell = FALSE` (default is `TRUE`) in `cell_spec`, it will define cell background color as `\cellcolor{}`, which doesn't work outside of a table, while for `text_spec`, the default value for `latex_background_in_cell` is `FALSE`.
+
+```{r}
+sometext <- strsplit(paste0(
+ "You can even try do do some crazy things like this paragraph. Although ",
+ "it's probably a useless feature but you may find it's fun to play with. :)"
+), " ")[[1]]
+text_formatted <- paste(
+ text_spec(sometext, color = spec_color(1:length(sometext), end = 0.8, option = "A")),
+ collapse = " ")
+
+# To display the text, type `r text_formatted` outside of the chunk
+```
+`r text_formatted`
+
# Grouped Columns / Rows
## 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)).
@@ -207,7 +268,7 @@
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, in kableExtra 0.3.0, you can specify `bold` & `italic` as you do in `row_spec()`.
+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, format = "latex", booktabs = T) %>%
kable_styling(latex_options = "striped") %>%
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index 666ff35..d84b4bc 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ
diff --git a/docs/use_kableExtra_with_formattable.Rmd b/docs/use_kableExtra_with_formattable.Rmd
index 1d71652..99f8c2f 100644
--- a/docs/use_kableExtra_with_formattable.Rmd
+++ b/docs/use_kableExtra_with_formattable.Rmd
@@ -48,7 +48,8 @@
mutate_if(is.numeric, function(x){
cell_spec(x, "html", color = spec_color(x), bold = T)
}) %>%
- kable("html", escape = F, align = "c") %>%
+ mutate(Species = cell_spec(Species, background = "red")) %>%
+ kable("html", col.names = c("A", "B", "C", "D", "DDDDDDDDDDD"), escape = F, align = "c") %>%
kable_styling("condensed", full_width = F)
```
diff --git a/docs/use_kableExtra_with_formattable.html b/docs/use_kableExtra_with_formattable.html
index 1dff26c..4ea68ad 100644
--- a/docs/use_kableExtra_with_formattable.html
+++ b/docs/use_kableExtra_with_formattable.html
@@ -11,7 +11,7 @@
<meta name="author" content="Hao Zhu" />
-<meta name="date" content="2017-10-17" />
+<meta name="date" content="2017-10-21" />
<title>Use kableExtra with formattable</title>
@@ -119,7 +119,7 @@
<h1 class="title toc-ignore">Use kableExtra with formattable</h1>
<h4 class="author"><em>Hao Zhu</em></h4>
-<h4 class="date"><em>2017-10-17</em></h4>
+<h4 class="date"><em>2017-10-21</em></h4>
</div>
@@ -188,14 +188,12 @@
<span style="display: block; padding: 0 4px; border-radius: 4px; background-color: #ffcc6f">21.0</span>
</td>
<td style="text-align:left;">
-<div style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;-webkit-transform: rotate(60deg); -moz-transform: rotate(60deg); -ms-transform: rotate(60deg); -o-transform: rotate(60deg); transform: rotate(60deg);">
-6
+<div style="-webkit-transform: rotate(60deg); -moz-transform: rotate(60deg); -ms-transform: rotate(60deg); -o-transform: rotate(60deg); transform: rotate(60deg);">
+<span style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;">6</span>
</div>
</td>
<td style="text-align:left;">
-<div style=" font-style: italic;color: green;">
-160
-</div>
+<span style=" font-style: italic;color: green;">160</span>
</td>
<td style="text-align:left;width: 3cm; display: inline-block; ">
<span style="display: inline-block; direction: rtl; border-radius: 4px; padding-right: 2px; background-color: lightgreen; width: 62.86%">110</span>
@@ -209,14 +207,12 @@
<span style="display: block; padding: 0 4px; border-radius: 4px; background-color: #ffcc6f">21.0</span>
</td>
<td style="text-align:left;">
-<div style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;-webkit-transform: rotate(120deg); -moz-transform: rotate(120deg); -ms-transform: rotate(120deg); -o-transform: rotate(120deg); transform: rotate(120deg);">
-6
+<div style="-webkit-transform: rotate(120deg); -moz-transform: rotate(120deg); -ms-transform: rotate(120deg); -o-transform: rotate(120deg); transform: rotate(120deg);">
+<span style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;">6</span>
</div>
</td>
<td style="text-align:left;">
-<div style=" font-style: italic;color: green;">
-160
-</div>
+<span style=" font-style: italic;color: green;">160</span>
</td>
<td style="text-align:left;width: 3cm; display: inline-block; ">
<span style="display: inline-block; direction: rtl; border-radius: 4px; padding-right: 2px; background-color: lightgreen; width: 62.86%">110</span>
@@ -230,14 +226,12 @@
<span style="display: block; padding: 0 4px; border-radius: 4px; background-color: #ffa500">22.8</span>
</td>
<td style="text-align:left;">
-<div style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); -o-transform: rotate(180deg); transform: rotate(180deg);">
-4
+<div style="-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -ms-transform: rotate(180deg); -o-transform: rotate(180deg); transform: rotate(180deg);">
+<span style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;">4</span>
</div>
</td>
<td style="text-align:left;">
-<div style=" font-style: italic;color: green;">
-108
-</div>
+<span style=" font-style: italic;color: green;">108</span>
</td>
<td style="text-align:left;width: 3cm; display: inline-block; ">
<span style="display: inline-block; direction: rtl; border-radius: 4px; padding-right: 2px; background-color: lightgreen; width: 53.14%">93</span>
@@ -251,14 +245,12 @@
<span style="display: block; padding: 0 4px; border-radius: 4px; background-color: #ffc357">21.4</span>
</td>
<td style="text-align:left;">
-<div style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;-webkit-transform: rotate(240deg); -moz-transform: rotate(240deg); -ms-transform: rotate(240deg); -o-transform: rotate(240deg); transform: rotate(240deg);">
-6
+<div style="-webkit-transform: rotate(240deg); -moz-transform: rotate(240deg); -ms-transform: rotate(240deg); -o-transform: rotate(240deg); transform: rotate(240deg);">
+<span style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;">6</span>
</div>
</td>
<td style="text-align:left;">
-<div style=" font-weight: bold;color: red;">
-258
-</div>
+<span style=" font-weight: bold;color: red;">258</span>
</td>
<td style="text-align:left;width: 3cm; display: inline-block; ">
<span style="display: inline-block; direction: rtl; border-radius: 4px; padding-right: 2px; background-color: lightgreen; width: 62.86%">110</span>
@@ -272,14 +264,12 @@
<span style="display: block; padding: 0 4px; border-radius: 4px; background-color: #ffffff">18.7</span>
</td>
<td style="text-align:left;">
-<div style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;-webkit-transform: rotate(300deg); -moz-transform: rotate(300deg); -ms-transform: rotate(300deg); -o-transform: rotate(300deg); transform: rotate(300deg);">
-8
+<div style="-webkit-transform: rotate(300deg); -moz-transform: rotate(300deg); -ms-transform: rotate(300deg); -o-transform: rotate(300deg); transform: rotate(300deg);">
+<span style="color: white;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;text-align: center;">8</span>
</div>
</td>
<td style="text-align:left;">
-<div style=" font-weight: bold;color: red;">
-360
-</div>
+<span style=" font-weight: bold;color: red;">360</span>
</td>
<td style="text-align:left;width: 3cm; display: inline-block; ">
<span style="display: inline-block; direction: rtl; border-radius: 4px; padding-right: 2px; background-color: lightgreen; width: 100.00%">175</span>
@@ -296,277 +286,199 @@
mutate_if(is.numeric, function(x){
cell_spec(x, "html", color = spec_color(x), bold = T)
}) %>%
- kable("html", escape = F, align = "c") %>%
+ mutate(Species = cell_spec(Species, background = "red")) %>%
+ kable("html", col.names = c("A", "B", "C", "D", "DDDDDDDDDDD"), escape = F, align = "c") %>%
kable_styling("condensed", full_width = F)</code></pre>
+<pre><code>## Setting cell_spec format as html</code></pre>
<table class="table table-condensed" style="width: auto !important; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:center;">
-Sepal.Length
+A
</th>
<th style="text-align:center;">
-Sepal.Width
+B
</th>
<th style="text-align:center;">
-Petal.Length
+C
</th>
<th style="text-align:center;">
-Petal.Width
+D
</th>
<th style="text-align:center;">
-Species
+DDDDDDDDDDD
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(66, 190, 113, 1);">
-5.1
-</div>
+<span style=" font-weight: bold;color: rgba(66, 190, 113, 1);">5.1</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(34, 168, 132, 1);">
-3.5
-</div>
+<span style=" font-weight: bold;color: rgba(34, 168, 132, 1);">3.5</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(59, 82, 139, 1);">
-1.4
-</div>
+<span style=" font-weight: bold;color: rgba(59, 82, 139, 1);">1.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-4.9
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">4.9</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(72, 37, 118, 1);">
-3
-</div>
+<span style=" font-weight: bold;color: rgba(72, 37, 118, 1);">3</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(59, 82, 139, 1);">
-1.4
-</div>
+<span style=" font-weight: bold;color: rgba(59, 82, 139, 1);">1.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(53, 95, 141, 1);">
-4.7
-</div>
+<span style=" font-weight: bold;color: rgba(53, 95, 141, 1);">4.7</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(52, 96, 141, 1);">
-3.2
-</div>
+<span style=" font-weight: bold;color: rgba(52, 96, 141, 1);">3.2</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(68, 1, 84, 1);">
-1.3
-</div>
+<span style=" font-weight: bold;color: rgba(68, 1, 84, 1);">1.3</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(65, 68, 135, 1);">
-4.6
-</div>
+<span style=" font-weight: bold;color: rgba(65, 68, 135, 1);">4.6</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(65, 68, 135, 1);">
-3.1
-</div>
+<span style=" font-weight: bold;color: rgba(65, 68, 135, 1);">3.1</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-1.5
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">1.5</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(34, 168, 132, 1);">
-5
-</div>
+<span style=" font-weight: bold;color: rgba(34, 168, 132, 1);">5</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(68, 191, 112, 1);">
-3.6
-</div>
+<span style=" font-weight: bold;color: rgba(68, 191, 112, 1);">3.6</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(59, 82, 139, 1);">
-1.4
-</div>
+<span style=" font-weight: bold;color: rgba(59, 82, 139, 1);">1.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(253, 231, 37, 1);">
-5.4
-</div>
+<span style=" font-weight: bold;color: rgba(253, 231, 37, 1);">5.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(253, 231, 37, 1);">
-3.9
-</div>
+<span style=" font-weight: bold;color: rgba(253, 231, 37, 1);">3.9</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(253, 231, 37, 1);">
-1.7
-</div>
+<span style=" font-weight: bold;color: rgba(253, 231, 37, 1);">1.7</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(253, 231, 37, 1);">
-0.4
-</div>
+<span style=" font-weight: bold;color: rgba(253, 231, 37, 1);">0.4</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(65, 68, 135, 1);">
-4.6
-</div>
+<span style=" font-weight: bold;color: rgba(65, 68, 135, 1);">4.6</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-3.4
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">3.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(59, 82, 139, 1);">
-1.4
-</div>
+<span style=" font-weight: bold;color: rgba(59, 82, 139, 1);">1.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(53, 183, 121, 1);">
-0.3
-</div>
+<span style=" font-weight: bold;color: rgba(53, 183, 121, 1);">0.3</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(34, 168, 132, 1);">
-5
-</div>
+<span style=" font-weight: bold;color: rgba(34, 168, 132, 1);">5</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-3.4
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">3.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-1.5
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">1.5</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(68, 1, 84, 1);">
-4.4
-</div>
+<span style=" font-weight: bold;color: rgba(68, 1, 84, 1);">4.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(68, 1, 84, 1);">
-2.9
-</div>
+<span style=" font-weight: bold;color: rgba(68, 1, 84, 1);">2.9</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(59, 82, 139, 1);">
-1.4
-</div>
+<span style=" font-weight: bold;color: rgba(59, 82, 139, 1);">1.4</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(49, 104, 142, 1);">
-0.2
-</div>
+<span style=" font-weight: bold;color: rgba(49, 104, 142, 1);">0.2</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
<tr>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-4.9
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">4.9</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(65, 68, 135, 1);">
-3.1
-</div>
+<span style=" font-weight: bold;color: rgba(65, 68, 135, 1);">3.1</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(33, 144, 141, 1);">
-1.5
-</div>
+<span style=" font-weight: bold;color: rgba(33, 144, 141, 1);">1.5</span>
</td>
<td style="text-align:center;">
-<div style=" font-weight: bold;color: rgba(68, 1, 84, 1);">
-0.1
-</div>
+<span style=" font-weight: bold;color: rgba(68, 1, 84, 1);">0.1</span>
</td>
<td style="text-align:center;">
-setosa
+<span style="border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: red;">setosa</span>
</td>
</tr>
</tbody>
diff --git a/man/cell_spec.Rd b/man/cell_spec.Rd
index edadea7..9d5e050 100644
--- a/man/cell_spec.Rd
+++ b/man/cell_spec.Rd
@@ -2,11 +2,18 @@
% Please edit documentation in R/cell_spec.R
\name{cell_spec}
\alias{cell_spec}
-\title{Specify Cell format}
+\alias{text_spec}
+\title{Specify Cell/Text format}
\usage{
cell_spec(x, format, bold = F, italic = F, monospace = F, color = NULL,
background = NULL, align = NULL, font_size = NULL, angle = NULL,
- tooltip = NULL, background_as_tile = TRUE)
+ tooltip = NULL, background_as_tile = TRUE,
+ latex_background_in_cell = TRUE)
+
+text_spec(x, format, bold = F, italic = F, monospace = F, color = NULL,
+ background = NULL, align = NULL, font_size = NULL, angle = NULL,
+ tooltip = NULL, background_as_tile = TRUE,
+ latex_background_in_cell = FALSE)
}
\arguments{
\item{x}{Things to be formated. It could be a vector of numbers or strings.}
@@ -14,35 +21,39 @@
\item{format}{Either "html" or "latex". It can also be set through
\code{option(knitr.table.format)}, same as \code{knitr::kable()}.}
-\item{bold}{A T/F value to control whether the text of the selected column
-need to be bolded.}
+\item{bold}{T/F for font bold.}
-\item{italic}{A T/F value to control whether the text of the selected column
-need to be emphasized.}
+\item{italic}{T/F for font italic.}
-\item{monospace}{A T/F value to control whether the text of the selected column
-need to be monospaced (verbatim)}
+\item{monospace}{T/F for font monospaced (verbatim)}
-\item{color}{A character string for column text color. Here please pay
+\item{color}{A character string for text color. Here please pay
attention to the differences in color codes between HTML and LaTeX.}
-\item{background}{A character string for column background color. Here please
-pay attention to the differences in color codes between HTML and LaTeX.}
+\item{background}{A character string for background color. Here please
+pay attention to the differences in color codes between HTML and LaTeX. Also
+note that in HTML, background defined in cell_spec won't cover the whole
+cell.}
-\item{align}{A character string for cell alignment. For HTML, possible values could
-be \code{l}, \code{c}, \code{r} plus \code{left}, \code{center}, \code{right}, \code{justify}, \code{initial} and \code{inherit}
-while for LaTeX, you can only choose from \code{l}, \code{c} & \code{r}.}
+\item{align}{A character string for cell alignment. For HTML, possible
+values could be \code{l}, \code{c}, \code{r} plus \code{left}, \code{center}, \code{right}, \code{justify},
+\code{initial} and \code{inherit} while for LaTeX, you can only choose
+from \code{l}, \code{c} & \code{r}.}
-\item{font_size}{Only if you want to specify font size locally in HTML.
-This feature is not available in LaTeX}
+\item{font_size}{j}
\item{angle}{0-360, degree that the text will rotate. Can be a vector.}
\item{tooltip}{A vector of strings to be displayed as tooltip.
-Of course, this feature is only available in HTML.}
+Obviously, this feature is only available in HTML.}
\item{background_as_tile}{T/F value indicating if you want to have round
-cornered tile as background.}
+cornered tile as background in HTML.}
+
+\item{latex_background_in_cell}{T/F value. It only takes effect in LaTeX
+when \code{background} provided, Default value is \code{TRUE}. If it's \code{TRUE}, the
+background only works in a table cell. If it's \code{FALSE}, it works outside of a
+table environment.}
}
\description{
Specify Cell format before it gets into kable
diff --git a/man/spec_font_size.Rd b/man/spec_font_size.Rd
index df2c1c0..aeacd93 100644
--- a/man/spec_font_size.Rd
+++ b/man/spec_font_size.Rd
@@ -4,7 +4,7 @@
\alias{spec_font_size}
\title{Generate common font size for continuous values}
\usage{
-spec_font_size(x, begin = 10, end = 20, na_font_size = "inherit")
+spec_font_size(x, begin = 8, end = 16, na_font_size = 12)
}
\arguments{
\item{x}{continuous vectors of values}