View source: R/ltx_tidy_table.R
ltx_tidy_table | R Documentation |
This function processes a LaTeX table by applying a series of transformations: adding a caption, adjusting placement, setting row spacing, rounding numbers, and wrapping numbers in math mode. It streamlines the formatting of LaTeX tables to ensure consistency in presentation and compliance with LaTeX math mode formatting.
ltx_tidy_table(
x,
tbl_note = "",
replace_idx = 1,
array_stretch = 1.2,
threshold = 10,
big_dec = 0,
small_dec = 2,
ruler_based = TRUE,
print_tbl = TRUE
)
x |
A character vector or list containing the LaTeX table input. |
tbl_note |
A string representing the caption to be added to the table. Defaults to "". |
replace_idx |
A numeric value representing the index at which to replace the table placement. Defaults to 1. |
array_stretch |
A numeric value to set the |
threshold |
A numeric value defining the threshold for rounding large
numbers. Numbers greater than or equal to this will use |
big_dec |
Number of decimal places for large numbers (>= threshold). Defaults to 0. |
small_dec |
Number of decimal places for small numbers (< threshold). Defaults to 2. |
print_tbl |
Logical, if |
The function works by applying the following steps:
ltx_capture_output(x)
: Converts the input LaTeX table into a manipulable format.
ltx_caption(tbl_note)
: Adds a caption to the LaTeX table.
ltx_placement(replace_idx)
: Adjusts the LaTeX table placement.
ltx_stretch(array_stretch)
: Sets the row spacing for the table by modifying the \\arraystretch
.
ltx_round_numbers(threshold, big_dec, small_dec)
: Rounds the numbers in the table based on the given threshold.
ltx_wrap_table_math()
: Wraps the numbers in LaTeX math mode ($number$
) where appropriate.
The processed LaTeX table is returned invisibly.
If print_tbl = TRUE
, the table is printed to the console.
## Not run:
# Example LaTeX input
latex_input <- c("\\begin{table}", "\\begin{tabular}{|c|c|}", "\\hline",
"Value & 1234 \\\\", "Temperature & 98.6 \\\\", "\\hline",
"\\end{tabular}", "\\end{table}")
# Tidy the table and print it
ltx_tidy_table(latex_input, tbl_note = "Sample Table", array_stretch = 1.5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.