ltx_stretch: Apply Array Stretch to a LaTeX Table

View source: R/ltx_stretch.R

ltx_stretchR Documentation

Apply Array Stretch to a LaTeX Table

Description

This function modifies a LaTeX table to adjust the row stretch (i.e., vertical space between rows) by appending the array stretch command (⁠\ra{}⁠) after the beginning of a tabular or tabularx environment. The ⁠\ra{}⁠ command is custom defined in my Overleaf as ⁠\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}⁠.

Usage

ltx_stretch(x, array_stretch = 1.2, verbose = TRUE, print_tbl = FALSE)

Arguments

x

A character vector representing a LaTeX table or an object that can be captured as LaTeX output using the ltx_capture_output() function.

array_stretch

Numeric. The row stretch factor to apply. Must be a positive number. Default is 1.2.

verbose

Logical. If TRUE, prints a message indicating the applied array stretch. Default is TRUE.

print_tbl

Logical. If TRUE, prints the modified LaTeX table to the console. Default is FALSE.

Details

The function searches for ⁠\begin{table}⁠ in the LaTeX table and appends the array stretch command ⁠\ra{}⁠ right after. If no such environment is found, an error is thrown. The function does not modify the ⁠\begin{table}⁠ environment.

Value

Returns the modified LaTeX table as a character vector with the array stretch applied. Invisibly returns the modified table.

Examples

## Not run: 
# Example LaTeX table
latex_table <- c("\\begin{table}",
"\\begin{tabular}{ccc}",
"\\hline", "1 & 2 & 3 \\\\",
"\\hline",
"\\end{tabular}",
"\\end{table}")
# Apply array stretch of 1.5
modified_table <- ltx_stretch(latex_table, array_stretch = 1.5, verbose = TRUE)

# Print the modified table
ltx_stretch(latex_table, array_stretch = 1.5, print_tbl = TRUE)

## End(Not run)

AndreSjuve/texaid documentation built on Oct. 20, 2024, 6:17 a.m.