Uni-table formatting help

Hi,

I am having a go at the uni-table package (hi @dominik.pantucek! :slight_smile: ). This styling:

(uni-table->string tbl
                   #:table-border '(solid light)
                   #:col-borders '((solid left heavy))
                   #:row-borders '((heavy solid)(light solid))
                   #:row-style '((#:bg DarkGrey)()...))

results in the picture below.

  1. Notice that the last column has a "light" border on the right. I'd like to have the last column have both left and right borders "heavy". How can I do that?

  2. I'd like my default style to alternate 2 colors on rows (grey, white, grey, white ...) to improve readability. But I don't know how many rows there will be in advance. Is there already a way to do that or should I cook up something of my own?

  3. As I understand it from the docs, there currently is no facility to style individual cells, right?

I have a strong interest in this package, so if life doesn't get in the way too much I'll definitely attempt to contribute! Thanks for the good work!

1 Like

If you have the table, you ought to be able to compute a row-style (which is, after all, just quoted data) that has what you want based on the number of rows.

If you have the table, you ought to be able to compute a row-style (which is, after all, just quoted data) that has what you want based on the number of rows.

Thanks, I certainly can. I just asked because since Uni-table is a very new package, and I know Dominik is very prolific so perhaps some functionalities were not documented yet.

                   #:col-borders '((solid left heavy right heavy))

If you know the number of rows, it is really easy.

#lang racket

(require uni-table)

(define tbl
  `((sepal_width sepal_length petal_width petal_length species)
    ,@(for/list ((i (in-range 10)))
        '(5.1 3.5 1.4 0.2 Iris-setosa))))

(print-uni-table tbl
                   #:table-border '(solid light)
                   #:col-borders '((solid left heavy right heavy))
                   #:row-borders '((heavy solid)(light solid))
                   #:row-style `((#:bg DarkGrey)
                                 ,@(for/list ((i (length tbl)))
                                     (if (odd? i)
                                         '(#:bg red)
                                         '(#:bg blue)))))

Screenshot from 2022-03-28 10-20-58

Btw, support for lazy and/or splicing styles is planned. If I only wasn't too busy it would already be implemented (alongside support for really large tables).

2 Likes

As you mentioned, it is a work in progress, however this is already there:

(define tbl2
  `((sepal_width sepal_length petal_width petal_length species)
    ,@(for/list ((i (in-range 10)))
        (for/list ((j (in-naturals))
                   (v '(5.1 3.5 1.4 0.2 Iris-setosa)))
          (uni-cell v
                    #:style (if (odd? (+ i j))
                                '(#:bg cyan)
                                '(#:bg green)))))))


(print-uni-table tbl2
                   #:table-border '(solid light)
                   #:col-borders '((solid left heavy right heavy))
                   #:row-borders '((heavy solid)(light solid))
                   #:row-style `((#:bg DarkGrey)
                                 ,@(for/list ((i (length tbl)))
                                     (if (odd? i)
                                         '(#:bg red)
                                         '(#:bg blue)))))

Screenshot from 2022-03-28 10-24-04

A bit extreme example, but you should get the point (see how the cell style overrides the row style as expected).

1 Like

Thanks so much for your very informative answers (and for the package, which looks like it's going to turn awesome)!