vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
211 stars 18 forks source link

LaTeX fragment option #333

Closed avitabilea closed 2 months ago

avitabilea commented 2 months ago

This is a minor request, but I would find it helpful if there were a LaTeX option that spit out a table fragment (i.e., just the rows with data, no column names, lines, etc.). This would allow users to build their own LaTeX table environment around output. Below I provide an example of how I currently hack my to do this:

library(tinytable)

# Generate example data
toy_data <- data.frame(
  id = 1:10,
  age = sample(18:65, 10, replace = TRUE),
  income = round(rnorm(10, mean = 50000, sd = 10000)),
  education = sample(c("High School", "Bachelor's", "Master's", "PhD"), 10, replace = TRUE)
)

# Print tinytable in LaTeX
table <- tt(toy_data) %>% save_tt("latex")
print(table)

table_cl <- sub("(?s).*?\\\\midrule(.*?)\\\\bottomrule.*", "\\1", table, perl = TRUE)
print(table_cl)

Thanks for all the work on this!

vincentarelbundock commented 2 months ago
tt(x) |> theme_tt("tabular")