Skip to contents

Adds a horizontal line at a specific position in the table.

Usage

tt_hline(table, y, start = NULL, end = NULL, stroke = TRUE)

Arguments

table

A typst_table object.

y

Position of the line (0 = top of table, 1 = below header, 2 = below first data row, etc.).

start

Starting column for partial line (0-indexed, inclusive).

end

Ending column for partial line (0-indexed, inclusive).

stroke

Line style: TRUE for default, color name, or full stroke spec like "2pt + red".

Value

The modified typst_table object.

Examples

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

# Add colored line
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_hline(1, stroke = "blue")
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   table.hline(stroke: 1pt),
#>   [mpg], [cyl], [disp],
#>   table.hline(stroke: 0.5pt),
#>   table.hline(stroke: 1pt + blue),
#>   [21], [6], [160],
#>   [21], [6], [160],
#>   [22.8], [4], [108],
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#>   table.hline(stroke: 1pt)
#> ) 

# Partial line spanning some columns
tt(mtcars[1:5, 1:3], rownames = FALSE) |>
  tt_hline(1, start = 0, end = 2)
#> #table(
#>   columns: (1fr, 1fr, 1fr),
#>   stroke: none,
#>   table.hline(stroke: 1pt),
#>   [mpg], [cyl], [disp],
#>   table.hline(stroke: 0.5pt),
#>   table.hline(start: 0, end: 3),
#>   [21], [6], [160],
#>   [21], [6], [160],
#>   [22.8], [4], [108],
#>   [21.4], [6], [258],
#>   [18.7], [8], [360],
#>   table.hline(stroke: 1pt)
#> )