Skip to contents

Applies formatting to one or more rows. Use row = 0 to style the header row.

Usage

tt_row(
  table,
  row,
  bold = NULL,
  italic = NULL,
  color = NULL,
  fill = NULL,
  align = NULL,
  font_size = NULL,
  rotate = NULL,
  inset = NULL,
  stroke = NULL,
  hline_above = NULL,
  hline_below = NULL
)

Arguments

table

A typst_table object.

row

Integer vector of row numbers to style. Use 0 for the header row, 1 to n for data rows. Use negative indices to target tt_header_above() rows: -1 is the innermost header_above (closest to the main header), -2 is the next row up, etc.

bold

Logical. Make text bold.

italic

Logical. Make text italic.

color

Text color.

fill

Fill color.

align

Row alignment override.

font_size

Font size.

rotate

Rotation angle (e.g., "90deg", 90, "1.5rad").

inset

Cell padding (e.g., "10pt", "5pt 8pt").

stroke

Stroke (border) specification for the cell(s). Can be TRUE for default 1pt black, a color, a Typst stroke spec like "2pt + blue", or a Typst dictionary like "(bottom: 1pt)".

hline_above

Add horizontal line above the row. Can be TRUE for default line or a stroke specification.

hline_below

Add horizontal line below the row.

Value

The modified typst_table object.

Examples

# Style header row
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_row(0, bold = TRUE, fill = "gray")
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   table.hline(stroke: 1pt),
#>   table.cell(fill: gray)[*mpg*], table.cell(fill: gray)[*cyl*], table.cell(fill: gray)[*disp*],
#>   table.hline(stroke: 0.5pt),
#>   [21], [6], [160],
#>   [21], [6], [160],
#>   [22.8], [4], [108],
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#>   table.hline(stroke: 1pt)
#> ) 

# Highlight specific rows
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_row(c(1, 3, 5), fill = "#ffffcc")
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   table.hline(stroke: 1pt),
#>   [mpg], [cyl], [disp],
#>   table.hline(stroke: 0.5pt),
#>   table.cell(fill: rgb("#ffffcc"))[21], table.cell(fill: rgb("#ffffcc"))[6], table.cell(fill: rgb("#ffffcc"))[160],
#>   [21], [6], [160],
#>   table.cell(fill: rgb("#ffffcc"))[22.8], table.cell(fill: rgb("#ffffcc"))[4], table.cell(fill: rgb("#ffffcc"))[108],
#>   [21.4], [6], [258],
#>   table.cell(fill: rgb("#ffffcc"))[18.7], table.cell(fill: rgb("#ffffcc"))[8], table.cell(fill: rgb("#ffffcc"))[360],
#>   table.hline(stroke: 1pt)
#> ) 

# Add horizontal lines
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_row(3, hline_above = TRUE, hline_below = TRUE)
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   table.hline(stroke: 1pt),
#>   [mpg], [cyl], [disp],
#>   table.hline(stroke: 0.5pt),
#>   [21], [6], [160],
#>   [21], [6], [160],
#>   table.hline(),
#>   table.hline(),
#>   [22.8], [4], [108],
#>   table.hline(),
#>   table.hline(),
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#>   table.hline(stroke: 1pt)
#> )