Skip to contents

Applies formatting to individual cells. Allows for precise control over cell appearance including spanning multiple rows or columns.

Usage

tt_cell(
  table,
  row,
  column,
  bold = NULL,
  italic = NULL,
  color = NULL,
  fill = NULL,
  align = NULL,
  font_size = NULL,
  rotate = NULL,
  inset = NULL,
  stroke = NULL,
  colspan = 1,
  rowspan = 1,
  content = NULL
)

Arguments

table

A typst_table object.

row

Row number (1-indexed for data rows, 0 for header). 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. The column is normalized to the start of the header group it falls within.

column

Column specification: integer index or column name.

bold

Logical. Make text bold.

italic

Logical. Make text italic.

color

Text color.

fill

Fill color.

align

Cell alignment.

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. Can be TRUE for default 1pt black, a color, a Typst stroke spec like "2pt + blue", or a Typst dictionary like "(bottom: 1pt)".

colspan

Number of columns to span (default 1).

rowspan

Number of rows to span (default 1).

content

Optional content to replace cell value.

Value

The modified typst_table object.

Examples

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

# Cell spanning multiple columns
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_cell(1, 1, colspan = 2, content = "Combined")
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   table.hline(stroke: 1pt),
#>   [mpg], [cyl], [disp],
#>   table.hline(stroke: 0.5pt),
#>   table.cell(colspan: 2)[Combined], [6], [160],
#>   [21], [6], [160],
#>   [22.8], [4], [108],
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#>   table.hline(stroke: 1pt)
#> )