style_tt | R Documentation |
Style a Tiny Table
style_tt(
x,
i = NULL,
j = NULL,
bold = FALSE,
italic = FALSE,
monospace = FALSE,
underline = FALSE,
strikeout = FALSE,
color = NULL,
background = NULL,
fontsize = NULL,
align = NULL,
alignv = NULL,
colspan = NULL,
rowspan = NULL,
indent = NULL,
line = NULL,
line_color = "black",
line_width = 0.1,
finalize = NULL,
tabularray_inner = NULL,
tabularray_outer = NULL,
bootstrap_class = NULL,
bootstrap_css = NULL,
bootstrap_css_rule = NULL,
output = NULL,
...
)
x |
A table object created by |
i |
Numeric vector, logical matrix, or string..
|
j |
Column indices where the styling should be applied. Can be:
|
bold |
Logical; if |
italic |
Logical; if |
monospace |
Logical; if |
underline |
Logical; if |
strikeout |
Logical; if |
color |
Text color. There are several ways to specify colors, depending on the output format.
|
background |
Background color. Specified as a color name or hexadecimal code. Can be |
fontsize |
Font size in em units. Can be |
align |
A single character or a string with a number of characters equal to the number of columns in |
alignv |
A single character specifying vertical alignment. Valid characters include 't' (top), 'm' (middle), 'b' (bottom). |
colspan |
Number of columns a cell should span. |
rowspan |
Number of rows a cell should span. |
indent |
Text indentation in em units. Positive values only. |
line |
String determines if solid lines (rules or borders) should be drawn around the cell, row, or column.
|
line_color |
Color of the line. See the |
line_width |
Width of the line in em units (default: 0.1). |
finalize |
A function applied to the table object at the very end of table-building, for post-processing. For example, the function could use regular expressions to add LaTeX commands to the text version of the table hosted in |
tabularray_inner |
A string that specifies the "inner" settings of a tabularray LaTeX table. |
tabularray_outer |
A string that specifies the "outer" settings of a tabularray LaTeX table. |
bootstrap_class |
String. Bootstrap table class such as |
bootstrap_css |
Character vector. CSS style declarations to be applied to every cell defined by |
bootstrap_css_rule |
String. Complete CSS rules (with curly braces, semicolon, etc.) that apply to the table class specified by the |
output |
Apply style only to the output format specified by this argument. |
... |
extra arguments are ignored |
This function applies styling to a table created by tt()
. It allows customization of text style (bold, italic, monospace), text and background colors, font size, cell width, text alignment, column span, and indentation. The function also supports passing native instructions to LaTeX (tabularray) and HTML (bootstrap) formats.
An object of class tt
representing the table.
Markdown and Word tables only support these styles: italic, bold, strikeout. The width
argument is also unavailable
Moreover, the style_tt()
function cannot be used to style headers inserted by the group_tt()
function;
instead, you should style the headers directly in the header definition using markdown syntax:
group_tt(i = list("*italic header*" = 2))
. These limitations are due to the fact that there is no markdown
syntax for the other options, and that we create Word documents by converting a markdown table to .docx
via the Pandoc software.
if (knitr::is_html_output()) options(tinytable_print_output = "html")
library(tinytable)
tt(mtcars[1:5, 1:6])
# Alignment
tt(mtcars[1:5, 1:6]) |>
style_tt(j = 1:5, align = "lcccr")
# Colors and styles
tt(mtcars[1:5, 1:6]) |>
style_tt(i = 2:3, background = "black", color = "orange", bold = TRUE)
# column selection with `j``
tt(mtcars[1:5, 1:6]) |>
style_tt(j = 5:6, background = "pink")
tt(mtcars[1:5, 1:6]) |>
style_tt(j = "drat|wt", background = "pink")
tt(mtcars[1:5, 1:6]) |>
style_tt(j = c("drat", "wt"), background = "pink")
tt(mtcars[1:5, 1:6], theme = "void") |>
style_tt(
i = 2, j = 2,
colspan = 3,
rowspan = 2,
align = "c",
alignv = "m",
color = "white",
background = "black",
bold = TRUE)
tt(mtcars[1:5, 1:6], theme = "void") |>
style_tt(
i = 0:3,
j = 1:3,
line = "tblr",
line_width = 0.4,
line_color = "teal")
tt(mtcars[1:5, 1:6], theme = "bootstrap") |>
style_tt(
i = c(2, 5),
j = 3,
strikeout = TRUE,
fontsize = 0.7)
tt(mtcars[1:5, 1:6]) |>
style_tt(bootstrap_class = "table table-dark table-hover")
inner <- "
column{1-4}={halign=c},
hlines = {fg=white},
vlines = {fg=white},
cell{1,6}{odd} = {bg=teal7},
cell{1,6}{even} = {bg=green7},
cell{2,4}{1,4} = {bg=red7},
cell{3,5}{1,4} = {bg=purple7},
cell{2}{2} = {r=4,c=2}{bg=azure7},
"
tt(mtcars[1:5, 1:4], theme = "void") |>
style_tt(tabularray_inner = inner)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.