tableRule: Work with rules in tables

tableRuleR Documentation

Work with rules in tables

Description

In LaTeX, "rules" are horizontal lines in a table. These functions let rules be extracted or modified.

Usage

find_rules(table)

rules(table, idx = find_rules(table))

find_rule(table, row)

rule(table, row)

rule(table, row, asis = FALSE, idx = find_rules(table)) <- value

Arguments

table

A tabular-like environment to work with.

idx

A list of indices as produced by find_rules().

row

The rules will precede the contents of this row. The rule after the final row uses row = tableNrow(table) + 1.

asis

Should a newline be added after the value? If asis = TRUE, it will not be.

value

The content to be inserted into the cell. This can be a LaTeX2 object, or a character string that will be converted to one.

Value

find_rules() returns a list of LaTeX2range objects giving the locations of the rules before each line. The last item in the list gives the location of any rules after the last line.

rules(table) returns a list of the rules before each row. The last entry will be the rule(s) following the last row.

find_rule(table, row) returns a LaTeX2range for the rule before row, not including the final whitespace.

rule(table, row) returns the rule(s) before row.

See Also

Use index_to_path() to convert to a path.

Examples

latex <- kableExtra::kbl(mtcars[1:2, 1:2], format = "latex")
parsed <- parseLatex(latex)
table <- parsed[[find_tabular(parsed)]]
table <- prepare_table(table)
find_rules(table)

rules(table)

find_rule(table, 1)

rule(table, 1)

rule(table, 2) <- "\\midrule"
table

parseLatex documentation built on June 8, 2025, 10:19 a.m.