ltx_resize: Resize LaTeX Tabular Environments

View source: R/ltx_resize.R

ltx_resizeR Documentation

Resize LaTeX Tabular Environments

Description

This function wraps LaTeX tabular-like environments (e.g., tabular, tabularx, longtable) with a ⁠\resizebox⁠ command to resize them to fit the ⁠\linewidth⁠. The function excludes resizing for table environments to prevent undesired behavior. This is useful for ensuring tables are properly scaled within the document margins in LaTeX.

Usage

ltx_resize(x, print_tbl = FALSE, verbose = TRUE)

Arguments

x

A character vector representing the LaTeX code that contains tabular environments.

print_tbl

A logical flag indicating whether the modified table should be printed to the console and copied to the clipboard. Defaults to FALSE.

verbose

A logical flag to indicate whether messages should be printed to the console. Defaults to TRUE.

Details

The function works by identifying lines containing ⁠\begin{tabular}⁠, ⁠\begin{tabularx}⁠, or other supported tabular environments (excluding table), and wraps these environments with a ⁠\resizebox{\\linewidth}{!}{...}⁠ command. It ensures that the ⁠\end{tabular}⁠ line is closed properly.

Value

The modified LaTeX code with the resizebox applied around tabular environments, returned as a character vector. If print_tbl is TRUE, the modified table is printed to the console.

Examples

## Not run: 
# Example LaTeX table code
x <- c("\\begin{tabular}{ll}", "A & B \\\\", "\\end{tabular}")
ltx_resize(x)

## End(Not run)

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