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

`theme_tt()`: Raw `tabular` without any `tabularray` #268

Closed vincentarelbundock closed 4 months ago

vincentarelbundock commented 5 months ago

Tabularray is cool, but in the spirit of minimal package dependencies (and coauthors who don't like changing latex preambles) it might be nice to have a minimal latex theme that outputs raw tabular code (without any formatting that depends on tabularray.)

Originally posted by @mjdcurtis in https://github.com/vincentarelbundock/tinytable/issues/30#issuecomment-2158178124

vincentarelbundock commented 5 months ago

@mjdcurtis, that sounds like a good idea.

One option that could be good is to add a tabularray=TRUE (default) argument to this function:

https://github.com/vincentarelbundock/tinytable/blob/main/R/theme_tt.R#L17

It would be easy to use the utilities here to drop appropriate lines from the template and replace tblr by tabular.

I'm marking this as "Good First Issue" because most people should be able to implement this without deep knowledge of the code base.

vincentarelbundock commented 4 months ago

In version 0.3.0.18 from Github, theme_tt("tabular") returns a pure tabular environment, without requiring booktabs or tabularray.

mjdcurtis commented 4 months ago

The tabular theme is fantastic if you follow the steps on the website.

If you use modelsummary, it doesn't work without some manual editing of the .tex output:


library(modelsummary)
library(tinytable)

reg<-lm(data=mtcars,mpg~cyl) 

# still has talltblr syntax after begin
modelsummary(reg)|> theme_tt('tabular') |> print('latex')

# still has talltblr syntax after begin
# ends with talltblr
modelsummary(reg, stars =  c('*' = .1, '**' = .05, '***' = 0.01))|> 
  theme_tt('tabular') |> print('latex')
mjdcurtis commented 4 months ago

If it helps, I was running something like:

simplify_table<-function(x){
  ncol<-gregexpr('\\&', raw[which(raw=='\\toprule')+1])[[1]] |> length()
  c(paste0('\\begin{tabular}{l',paste0(rep('r',ncol),collapse=''),'}'),
    x[which(x=='\\toprule'):which(x=='\\bottomrule')],
    '\\end{tabular}')
}

modelsummary(reg) |> print('latex')|>  capture.output() |>simplify_table()

But it would not work in all cases, e.g. I removed group_tt commands etc. before running this.

(Please disregard if not helpful / annoying!)

vincentarelbundock commented 4 months ago

This is fixed upstream in tinytable