Tinderbox Forum

Summary Display: TableExpression .format() strips leading spaces

This is only a minor cosmetic issue but it’s stumping me…

I’m trying to get .format() working to right-align a column of numbers in a $TableExpression, and I can’t find the correct incantation… What am I doing wrong please? (I’ve searched the forum and can’t find this being addressed before…)

What I want is a column of numbers in a Summary table to be right aligned, with leading spaces/zeroes. E.g.

#     Result
1.     12.34
2.      1.23
3.    -12.34
4.     -1.23

Now, away from the Summary Table context (e.g. in a string attribute which can be displayed in outline columns or elsewhere), I can get this to work with:

$MyString = $MyNumber.format(2,10," ")

In the screenshot below, you can see that both $MyString (with .format(2,10," ") and $FormattedStr (with .format(2,10,"-") produce the expected results in outline columns:

($FormattedNumber is a number attribute with .format(2,10," ") and as you can the precision is respected, but not the leading padding, which isn’t unexpected as it’s not a string).

So far so good. But when I feed this into a $TableExpression, $FormattedSgt’s indenting is respected, but the leading spaces in $MyString are stripped out.

The $TableExpression is very simple:

$TableExpression='$Name + "|" + $MyNumber + "|" + $FormattedNumber + "|" + $MyString + "|" + $FormattedStr';

So there appears to be a difference in the way $TableExpression deals with .format(2,10," ") and .format(2,10,"-") compared to elsewhere in TBX.

Am I missing something?

Many thanks for your help.

[Edit: I thought I’d found a solution by using a non-breaking space in the format string, but that turns out to crash Tinderbox reliably, unfortunately.]

This is something for @eastgate to look into.

Indeed, and I shall report it in due course, but it’s a subsidiary issue to the main subject of the post (summary tables strip out leading spaces), so I’ll wait until I find out whether that’s caused by user error, or is intended behaviour. If it’s not, then I’ll report both at the same time.

Do you experience the same behaviour?



1 Like

I don’t believe container tables (as in $TableExpression) offer column right/left justification though it could be archived in part by using the same number of digits before/after the decimal by formatting the the numbers.

But, at present, don’t waste time looking for container table column format controls—there aren’t any, as Tinderbox decides.

Hi Mark,

As you can see that’s exactly the approach I’ve taken: formatting the number string to fake alignment.

The issue I came across is that the Summary Table treats a string formatted with " " and "-" (or any other non-space character) differently, stripping the one, but not the other. (Both work correctly in other contexts.)

If there isn’t a mistake in my code, then I’ll report it as an edge case to Mark: it may be intended (I suspect it may be that it’s being overridden by the table code to remove the occasional unsightly accidental stray space at the beginning of a string)

Either way, it’s not a big issue as I now know to use another character for the format.



Ah, I suspect Tinderbox is ‘tidying’ your values by trimming padding whitespace.

The real issue is container tables don’t offer user-defined per-column layout/formatting. I guess that’s a feature request for you to make.

Please don’t misread the last as a negative opinion, but rather it is most useful for someone with the actual real-world need for a feature to make the case as inevitably there are specifics to iron out. :slight_smile:

Not at all negative.

As usual, when one first comes across an issue, it’s not easy to distinguish between “I can’t get this to work”, “I’m misunderstanding how it is supposed to work”, and “It’s not working the way it should.” Impossible to know which it is without posting on here for other people’s views.

I’m not sure user-defined per-column layout/formatting is worthy of a feature request on its own, (now I know what’s going on I’m happy with using .format), but I’ll mention it in my email.

1 Like