I'm printing out huge tables of numbers aligned to the centre of each cell.
This looks fine except when negative numbers start to appear.
The align to centre then doesn't look quite right as the negative sign casues a bit of offset.
The way around this is to align to the decimal point by putting a decimal tab in the middle of the cell and aligning left to it.
However, I am currently only doing this by eye.
How can I work out programatically where to put the decimal tab, based on the length of the number?
The numbers will all have the same number of decimal places in each column but can have different number of places in different columns/tables.
I forgot that the style was still applied.
The first table is aligned by the Style (Normal + Centred)
The second table still has the Style applied but I have put Decimal tabs over each column and aligned to the left.
The net result is that the columns are aligned to the centre (or near enough) and all the decimal points line up.
I am running Word 2000.
If you are running Word XP it will probably give a slight change to the description of the style in the second table.
The important thing is the decimal tab.
You can add them by either double clicking in the horizontal ruler and selecting decimal Tab then typing the position you want.
Or you can click the tab icon (to the left of the horizontal ruler) several times until it looks like an inverted 'T' with a dot on the right.
The complicated bit is knowing where to put the decimal tab though.
The tabs would be in different positions depending upon the number of decimal places in the column.
I suppose I could manually work it out then have a lookup table, but calculating it seems better.
Psuedo code of what I am trying to do
Code:
A = Column Width
B = String Width
Tab position = (A / 2) - (B / 2)
Although the tab wouldnt be exactly in this position due to the decimal place being after the negative sign and the first 0
Last edited by agmorgan; Aug 25th, 2005 at 06:28 PM.