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, full stroke spec like "2pt + red", or FALSE to explicitly remove a line (e.g., suppress a booktabs rule).

Value

The modified typst_table object.

Examples

# Add line below header
tt(mtcars[1:5, 1:3]) |>
  tt_hline(1)
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: 1pt),
#>     [mpg], [cyl], [disp],
#>     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]) |>
  tt_hline(1, stroke = "blue")
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: 1pt),
#>     [mpg], [cyl], [disp],
#>     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]) |>
  tt_hline(1, start = 0, end = 2)
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: 1pt),
#>     [mpg], [cyl], [disp],
#>     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)
#> ) 

# Remove top booktabs rule
tt(mtcars[1:5, 1:3]) |>
  tt_hline(0, stroke = FALSE)
#> #table(
#>   columns: (auto, auto, auto),
#>   stroke: none,
#>   table.header(
#>     table.hline(stroke: none),
#>     [mpg], [cyl], [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)
#> )