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_label = TRUE
)

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_label

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

Value

The modified typst_table object.

Examples

# Group rows with a label
tt(mtcars[1:10, 1:3], rownames = FALSE) |>
  tt_pack_rows("4 Cylinders", 1, 5) |>
  tt_pack_rows("6 Cylinders", 6, 10)
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   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], rownames = FALSE) |>
  tt_pack_rows(index = c("4 Cylinders" = 5, "6 Cylinders" = 5))
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   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)
#> )