In LaTeX, "rules" are horizontal lines in a table. These functions let rules be extracted or modified.
Usage
find_rules(table)
rules(table)
find_rule(table, row)
rule(table, row)
rule(table, row, asis = FALSE) <- value
Arguments
- table
A tabular-like environment to work with.
- 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 the indices
of rules before each row, including the whitespace
following each one.
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 the indices
of the rule(s) before row
.
rule(table, row)
returns the indices
rule(s) before row
.
Examples
latex <- kableExtra::kbl(mtcars[1:2, 1:2], format = "latex")
parsed <- parseLatex(latex)
table <- parsed[[find_tabular(parsed)]]
table
#> ENVIRONMENT: \begin{tabular}[t]{l|r|r}
#> \hline
#> & mpg & cyl\\
#> \hline
#> Mazda RX4 & 21 & 6\\
#> \hline
#> Mazda RX4 Wag & 21 & 6\\
#> \hline
#> \end{tabular}
find_rules(table)
#> [[1]]
#> [1] 6 7 8 9
#>
#> [[2]]
#> [1] 19 20
#>
#> [[3]]
#> [1] 36 37
#>
#> [[4]]
#> [1] 55 56
#>
rules(table)
#> [[1]]
#> \hline
#>
#>
#> [[2]]
#> \hline
#>
#>
#> [[3]]
#> \hline
#>
#>
#> [[4]]
#> \hline
#>
#>
find_rule(table, 1)
#> [1] 6 7 8 9
rule(table, 1)
#> \hline
#>
rule(table, 2) <- "\\midrule"
table
#> ENVIRONMENT: \begin{tabular}[t]{l|r|r}
#> \hline
#> & mpg & cyl\\
#> \midrule
#> Mazda RX4 & 21 & 6\\
#> \hline
#> Mazda RX4 Wag & 21 & 6\\
#> \hline
#> \end{tabular}