带有 xsl-fo 的 scala:对齐 table 列中的 decimasl

scala with xsl-fo: Aligning decimasl in table column

我正在使用 scala 和 xsl-fo 生成 pdf。

我有一个 table,其中有一列具有数值。我的要求是以小数点对齐的方式显示数字。

所以我的方法是添加前导 spaces 以便我们在小数点前有相同数量的字符。 以“0”为主角,我有以下显示,一切似乎都有效。

但是如果 space 为空,事情就无法正常工作,因为空 space 会被丢弃:

有没有办法让空 space 正常工作,或者是否有更好的方法来实现 objective?

简短的回答是使用表格数字(a.k.a。表格数字,参见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)。

你没有说你使用的是哪个格式化程序,但是使用 AH 格式化程序,你会使用 font-variant="tabular-nums" 来获取表格数字。

你可以用普通的 space 试试 white-space-treatment="preserve",但是普通的 space 和图形 space 可能有不同的宽度,这取决于使用的字体。

您的格式化程序可能还支持或改为支持 table 单元格中 text-align 的字符串值,并为您对齐 . 上的单元格内容。如果您使用的是 AH Formatter,您还可以指定 axf:text-align-string 来指定所有对齐的字符串在其 table 列中的对齐方式。 (参见 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