Please consider the following example. It is to color coordinate table cell contents.

| Name | Age | Color |
| John |  25 | red   |
| Mary |  30 | green |
| Tom  |  40 | blue  |

#+TBLFM: $3='(progn (cond ((string= $3 "red") "[:foreground \"red\"]")
                       ((string= $3 "green") "[:foreground \"green\"]")
                       ((string= $3 "blue") "[:foreground \"blue\"]")
                       (t "")))::

It does not seem to work. How can I get it to work?

What's the simplest way to colorize text in an org-mode table cell depending on say a threshold value in the cell? Alternative solutions welcome. It can't be this difficult.

Something along these lines does not seem to work either:

| Column 1 | Column 2 |
| foo      |       42 |
| bar      |       69 |
| baz      |     1337 |
#+TBLFM: $2='(format "[%s]" (propertize $2 'font-lock-face '(:foreground "red")))

The format of the cell content changes but not the color. WTH??!!

Rather than spending an inordinate amount of time on this seemingly trivial problem, I got the above examples from ChatGPT. None of which work. Hmm.. I now have a collection of such examples all from various queries of ChatGPT to try and none of them work.

  • 2
    Showing code that does not work does not tell what you are looking for. You need to say what you expect to happen. In particular, what does "color coordinate table cell contents" mean? It appears that you want something in the first row to be colored red, something in the second row to be colored green and so on. But it is not clear what that something is supposed to be: every cell in the row? the cell in the third column of the row? something else?
    – NickD
    Apr 30, 2023 at 17:24
  • Isn't it obvious what this example ought to do? The table formula (TBLFM) applied to the 3rd column should yield colored text in the respective rows. It's not happening.
    – user31292
    Apr 30, 2023 at 17:47
  • 2
    Not to me. As I said, showing non-working code without explaining what it is supposed to do is worse than useless: one has to figure out what you want (mostly by guessing at this point) and then figure out how to modify the code to do that; if one guesses wrong about what you want (as I did in your previous question), then I can go down the wrong path for quite a while before realizing that you meant something else. So by all means, include what you tried: but first explain what you want to accomplish as completely and as precisely as possible.
    – NickD
    Apr 30, 2023 at 18:06
  • 1
  • I'm aware of those threads. The solutions are so dastardly complicated. I wish to give the question another shot. I'm looking for a very simple solution.
    – user31292
    May 1, 2023 at 12:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.