Skip to contents

Inserts a group label row and optionally indents the grouped rows. Useful for creating visual sections in the table.

Usage

tt_pack_rows(
  table,
  group_label = NULL,
  start_row = NULL,
  end_row = NULL,
  index = NULL,
  indent = TRUE,
  bold = TRUE,
  italic = NULL,
  color = NULL,
  fill = NULL,
  align = NULL,
  font_size = NULL,
  rotate = NULL,
  inset = NULL,
  stroke = NULL,
  hline_below = NULL
)

Arguments

table

A typst_table object.

group_label

The label text for the group (used with start_row/end_row).

start_row

First row number in the group (1-indexed).

end_row

Last row number in the group.

index

A named numeric vector for multiple groups (alternative style). Names are group labels, values are row counts. Example: c("Group A" = 3, "Group B" = 5) creates two groups where "Group A" covers rows 1-3 and "Group B" covers rows 4-8.

indent

Logical. Indent rows in the group (default TRUE).

bold

Logical. Make the group label bold (default TRUE).

italic

Logical. Make the group label italic.

color

Text color for the group label.

fill

Fill color for the group label row.

align

Alignment for the group label row.

font_size

Font size for the group label.

rotate

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

inset

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

stroke

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

hline_below

Add horizontal line below the group label. Can be TRUE for default line or a stroke specification.

Value

The modified typst_table object.

Examples

# Group rows with a label
tt(mtcars[1:10, 1:3]) |>
  tt_pack_rows("4 Cylinders", 1, 5) |>
  tt_pack_rows("6 Cylinders", 6, 10)
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: 1pt),
#>     [mpg], [cyl], [disp],
#>     table.hline(stroke: 0.5pt)
#>   ),
#>   table.cell(colspan: 3)[*4 Cylinders*],
#>   [#h(1em)21], [6], [160],
#>   [#h(1em)21], [6], [160],
#>   [#h(1em)22.8], [4], [108],
#>   [#h(1em)21.4], [6], [258],
#>   [#h(1em)18.7], [8], [360],
#>   table.cell(colspan: 3)[*6 Cylinders*],
#>   [#h(1em)18.1], [6], [225],
#>   [#h(1em)14.3], [8], [360],
#>   [#h(1em)24.4], [4], [146.7],
#>   [#h(1em)22.8], [4], [140.8],
#>   [#h(1em)19.2], [6], [167.6],
#>   table.hline(stroke: 1pt)
#> ) 

# Using index parameter (alternative style)
tt(mtcars[1:10, 1:3]) |>
  tt_pack_rows(index = c("4 Cylinders" = 5, "6 Cylinders" = 5))
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: 1pt),
#>     [mpg], [cyl], [disp],
#>     table.hline(stroke: 0.5pt)
#>   ),
#>   table.cell(colspan: 3)[*4 Cylinders*],
#>   [#h(1em)21], [6], [160],
#>   [#h(1em)21], [6], [160],
#>   [#h(1em)22.8], [4], [108],
#>   [#h(1em)21.4], [6], [258],
#>   [#h(1em)18.7], [8], [360],
#>   table.cell(colspan: 3)[*6 Cylinders*],
#>   [#h(1em)18.1], [6], [225],
#>   [#h(1em)14.3], [8], [360],
#>   [#h(1em)24.4], [4], [146.7],
#>   [#h(1em)22.8], [4], [140.8],
#>   [#h(1em)19.2], [6], [167.6],
#>   table.hline(stroke: 1pt)
#> ) 

# Styled group labels
tt(mtcars[1:10, 1:3]) |>
  tt_pack_rows("4 Cylinders", 1, 5, fill = "#e6f3ff", italic = TRUE) |>
  tt_pack_rows("6 Cylinders", 6, 10, fill = "#e6f3ff", italic = TRUE)
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: 1pt),
#>     [mpg], [cyl], [disp],
#>     table.hline(stroke: 0.5pt)
#>   ),
#>   table.cell(colspan: 3, fill: rgb("#e6f3ff"))[_*4 Cylinders*_],
#>   [#h(1em)21], [6], [160],
#>   [#h(1em)21], [6], [160],
#>   [#h(1em)22.8], [4], [108],
#>   [#h(1em)21.4], [6], [258],
#>   [#h(1em)18.7], [8], [360],
#>   table.cell(colspan: 3, fill: rgb("#e6f3ff"))[_*6 Cylinders*_],
#>   [#h(1em)18.1], [6], [225],
#>   [#h(1em)14.3], [8], [360],
#>   [#h(1em)24.4], [4], [146.7],
#>   [#h(1em)22.8], [4], [140.8],
#>   [#h(1em)19.2], [6], [167.6],
#>   table.hline(stroke: 1pt)
#> )