vincentarelbundock / tinytable

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

style_tt(align="d") and error Undefined color `si'. #262

Closed mjdcurtis closed 4 months ago

mjdcurtis commented 4 months ago

Excited to use the new package!

I am trying to use style_tt(align="d") but I am getting errors related to siunitx and colors.

If I use the recommended preamble, I get `Undefined control sequence.

\color `. If I load xcolor or siunitx, I get `Undefined color `si'.` It may be a dependency issue because I am using tinytex, which has minimal packages installed. See below for a minimum replicable example: R script ``` library(modelsummary) library(tinytable) setwd(this.path::here()) models <- list() models[['Bivariate']] <- lm(Girth ~ Height, data = trees) models[['Multivariate']] <- lm(Girth ~ Height + Volume, data = trees) latex<-modelsummary(models) |> theme_tt("tabular") |> style_tt(align="d")|> print('latex') |> capture.output() cat(latex,file="table.tex",sep="\n") ``` LaTeX code (tinytex, pdflatex) ``` \documentclass[12pt]{article} \usepackage{tabularray} \usepackage{float} \usepackage{graphicx} %\usepackage{xcolor} \usepackage[normalem]{ulem} %\usepackage{siunitx} %\UseTblrLibrary{booktabs,siunitx} \UseTblrLibrary{booktabs} \newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}} \newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}} \NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}} \begin{document} \input{table.tex} \end{document} ``` I get many error messages along the line of: ``` Undefined control sequence. \color {\lTblrCellBackgroundTl }\vrule width \dim_use:N \l_tmpa_d... l.40 \end ``` If I load xcolor or if I load siunitx, I get many error messages along the line of: ``` ./table.tex:40: Package xcolor Error: Undefined color `guard'. ./table.tex:40: Package xcolor Error: Undefined color `si'. ```
vincentarelbundock commented 4 months ago

Thanks for the report. I believe you need to make two changes. First, add this to your preamble after tabularray:

\UseTblrLibrary{siunitx}

(I added it to the documentation; it was missing.)

Then, you need to specify which columns you want to dot-align. It won't work with your first columns which is just words without dots.

tab |> style_tt(j = 2:3, align = "d")

let me know if that works for you

mjdcurtis commented 4 months ago

Great, specifying the columns works as expected!

Enjoying trying out the package, thanks.