Skip to contents

Sets global styling properties for the entire table including stroke (borders), fill, striped rows, and spacing.

Usage

tt_style(
  table,
  stroke = NULL,
  fill = NULL,
  striped = NULL,
  inset = NULL,
  row_gutter = NULL,
  column_gutter = NULL,
  position = NULL,
  full_width = FALSE
)

Arguments

table

A typst_table object.

stroke

Stroke (border) specification: TRUE for default 1pt black borders, a color name/hex for 1pt borders in that color, or a Typst stroke specification like "2pt + blue". When stroke is set, gap columns and separator lines from tt_header_above() are automatically suppressed.

fill

Fill color for the entire table.

striped

Logical. If TRUE, alternates row background colors for readability.

inset

Cell padding. Can be a single value (e.g., "5pt") or named vector for different padding on each side.

row_gutter

Vertical spacing between rows.

column_gutter

Horizontal spacing between columns.

position

Table position on page: "auto", "left", "center", "right".

full_width

Logical. If TRUE, table spans full page width.

Value

The modified typst_table object.

Examples

# Add borders and striped rows
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_style(stroke = TRUE, striped = TRUE)
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: 1pt + black,
#>   fill: (_, y) => if calc.odd(y) { rgb("#f5f5f5") },
#>   [mpg], [cyl], [disp],
#>   [21], [6], [160],
#>   [21], [6], [160],
#>   [22.8], [4], [108],
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#> ) 

# Custom border color and padding
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_style(stroke = "gray", inset = "8pt")
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: 1pt + gray,
#>   inset: 8pt,
#>   [mpg], [cyl], [disp],
#>   [21], [6], [160],
#>   [21], [6], [160],
#>   [22.8], [4], [108],
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#> )