# Uni-table formatting help

**URL:** <https://racket.discourse.group/t/uni-table-formatting-help/823>\
**Category:** Questions & Answers\
**Created:** [March 24, 2022, 12:23pm UTC](https://racket.discourse.group/t/uni-table-formatting-help/823 "2022-03-24T12:23:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [March 24, 2022, 12:23pm UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/1 "2022-03-24T12:23:13Z")

</div>

Hi,

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

```scheme
(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!

 ![table](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/0b198c8ff24a73631e5cabaa726f8a3a01fa645d.png)

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [March 27, 2022, 3:54pm UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/2 "2022-03-27T15:54:54Z")

</div>

> [@rscho](#):
>
> - 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?

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.

---

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [March 27, 2022, 10:20pm UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/3 "2022-03-27T22:20:57Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)\
**Post date:** [March 28, 2022, 8:09am UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/4 "2022-03-28T08:09:32Z")

</div>

> [@rscho](#):
>
> 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?

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

```

---

<div class="post-metadata">

**Author:** ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)\
**Post date:** [March 28, 2022, 8:23am UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/5 "2022-03-28T08:23:15Z")

</div>

> [@rscho](#):
>
> 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?

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

```racket
#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](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/4f1c88a704a031776bf3fb203a2ba10cd91238c5.png)

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).

---

<div class="post-metadata">

**Author:** ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)\
**Post date:** [March 28, 2022, 8:24am UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/6 "2022-03-28T08:24:55Z")

</div>

> [@rscho](#):
>
> As I understand it from the docs, there currently is no facility to style individual cells, right?

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

```racket
(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](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/c62368ad1ff22c63ccb3590f4b8204d43224e407.png)

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

---

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [March 28, 2022, 7:09pm UTC](https://racket.discourse.group/t/uni-table-formatting-help/823/7 "2022-03-28T19:09:47Z")

</div>

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