Home > Software engineering >  scala with xsl-fo: Aligning decimasl in table column
scala with xsl-fo: Aligning decimasl in table column

Time:05-28

I am working with scala and xsl-fo to generate pdfs.

I have a table with a column having numerical values. My requirement is to display numbers in a way such that their decimals align.

So my approach is add leading spaces so that we have same number of characters before decimal. With '0' as leading character, I have following display and things seem to work.

enter image description here

But with empty space, things don't work as empty spaces are discarded:

enter image description here

Is there a way to get empty spaces working OR if there is a better way to achieve the objective?

CodePudding user response:

The short answer is to use tabular numerals (a.k.a. tabular figures, see https://docs.microsoft.com/en-ie/typography/opentype/spec/features_pt#tnum) for the numbers and to pad the number using FIGURE SPACE,   (see https://en.wikipedia.org/wiki/Figure_space).

You don't say which formatter you are using, but with AH Formatter, you would use font-variant="tabular-nums" to get tabular numerals.

You could try white-space-treatment="preserve" with ordinary spaces, but an ordinary space and a figure space may have different widths, depending on the font used.

Your formatter might also or instead support a string value for text-align in table cells and align the cells' contents on the . for you. If you are using AH Formatter, you can also specify axf:text-align-string to specify how all of the aligned strings are aligned within their table column. (See https://www.antennahouse.com/xsl-fo-samples#axf-text-align-string-1 in the 'XSL-FO Samples Collection' at https://www.antennahouse.com/xsl-fo-samples)

  • Related