Themes for tinytable

Description

A theme is a function which applies a collection of transformations to a tinytable object. Whereas the other tinytable functions such as format_tt() and style_tt() aim to be output-agnostic, themes can be output-specific, only applying to LaTeX, HTML, or Typst, as needed.

Each theme can have specific arguments, which are passed to the theme_tt() function. See the "Arguments" section below.

Usage

theme_tt(x, theme, ...)

Arguments

x A tinytable object
theme

String. Name of the theme to apply. One of:

  • "grid": Vertical and horizontal rules around each cell.

  • "void": No rules

  • "bootstrap": Similar appearance to the default Bootstrap theme in HTML

  • "striped": Grey stripes on alternating rows

  • "tabular": No table environment (LaTeX) or Javascript/CSS (HTML)

  • "resize": Scale a LaTeX tinytable to fit the width argument.

  • "multipage": Long tables continue on the next page (LaTeX only)

  • "placement": Position of the table environment (LaTeX)

Additional arguments passed the themeing function. See the "Arguments" section below for a list of supported arguments for each theme.

Value

A modified tinytable object

Arguments

resize

  • width: A numeric value between 0.01 and 1, representing the proportion of the line width to use

  • direction: "down", "up", "both" A string indicating if the table should be scaled in one direction. For example, "down" will only resize the table if it exceeds

multipage

  • rowhead: Non-negative integer. The number of header rows to repeat on each page.

  • rowfoot: Non-negative integer. The number of footer rows to repeat on each page.

placement

  • latex_float: String to insert in square brackets after the LaTeX table environment, ex: "H", "htbp". The default value is controlled by a global option:

    • options(“tinytable_theme_placement_latex_float” = “H”)

Examples

library(tinytable)

library(tinytable)

x <- mtcars[1:4, 1:4]

# equivalent calls
tt(x, theme = "striped")
tinytable_gcdpr7528lwpyht5so2t
mpg cyl disp hp
21.0 6 160 110
21.0 6 160 110
22.8 4 108 93
21.4 6 258 110
tt(x) |> theme_tt("striped")
tinytable_vp2p3ftdgsuqd3z8xo7j
mpg cyl disp hp
21.0 6 160 110
21.0 6 160 110
22.8 4 108 93
21.4 6 258 110
# resize w/ argument
x <- cbind(mtcars[1:10,], mtcars[1:10,])
tt(x) |>
  theme_tt("resize", width = .9) |>
  print("latex")
\begin{table}
\centering
\resizebox{\ifdim\width>\linewidth 0.9\linewidth\else\width\fi}{!}{
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]},
}                     %% tabularray inner close
\toprule
mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb \\ \midrule %% TinyTableHeader
21.0 & 6 & 160.0 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4 & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4 \\
21.0 & 6 & 160.0 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4 & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4 \\
22.8 & 4 & 108.0 &  93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1 & 22.8 & 4 & 108.0 &  93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1 \\
21.4 & 6 & 258.0 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1 & 21.4 & 6 & 258.0 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1 \\
18.7 & 8 & 360.0 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2 & 18.7 & 8 & 360.0 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2 \\
18.1 & 6 & 225.0 & 105 & 2.76 & 3.460 & 20.22 & 1 & 0 & 3 & 1 & 18.1 & 6 & 225.0 & 105 & 2.76 & 3.460 & 20.22 & 1 & 0 & 3 & 1 \\
14.3 & 8 & 360.0 & 245 & 3.21 & 3.570 & 15.84 & 0 & 0 & 3 & 4 & 14.3 & 8 & 360.0 & 245 & 3.21 & 3.570 & 15.84 & 0 & 0 & 3 & 4 \\
24.4 & 4 & 146.7 &  62 & 3.69 & 3.190 & 20.00 & 1 & 0 & 4 & 2 & 24.4 & 4 & 146.7 &  62 & 3.69 & 3.190 & 20.00 & 1 & 0 & 4 & 2 \\
22.8 & 4 & 140.8 &  95 & 3.92 & 3.150 & 22.90 & 1 & 0 & 4 & 2 & 22.8 & 4 & 140.8 &  95 & 3.92 & 3.150 & 22.90 & 1 & 0 & 4 & 2 \\
19.2 & 6 & 167.6 & 123 & 3.92 & 3.440 & 18.30 & 1 & 0 & 4 & 4 & 19.2 & 6 & 167.6 & 123 & 3.92 & 3.440 & 18.30 & 1 & 0 & 4 & 4 \\
\bottomrule
\end{tblr}
}
\end{table}