Click to See Complete Forum and Search --> : [WORD] Align To Decimal
agmorgan
Aug 25th, 2005, 01:40 PM
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.
agmorgan
Aug 25th, 2005, 02:14 PM
I bit more digging and I think I might have to use something like
Selection.Rows.SpaceBetweenColumns
Selection.Information(wdHorizontalPositionRelativeToPage)
Selection.Information(wdHorizontalPositionRelativeToTextBoundary)
I can't fully work it out though, I think it might have something to do with returning different types of measurement points/twips/cm/in etc
RobDog888
Aug 25th, 2005, 02:24 PM
So you want all numbers aligned center with the deimal points? Can you post a sample?
agmorgan
Aug 25th, 2005, 03:38 PM
Table 1 is centred.
Table 2 is aligned to decimal.
This is just doing it by eye.
RobDog888
Aug 25th, 2005, 04:56 PM
Its being aligned correctly by the PIMMS + Left font?
agmorgan
Aug 25th, 2005, 05:24 PM
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.
RobDog888
Aug 25th, 2005, 05:49 PM
You can set a decimal tab via code like so.
Selection.ParagraphFormat.TabStops(InchesToPoints(0.35)).Position = InchesToPoints(0.35)
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(0.35), Alignment:=wdAlignTabDecimal, Leader:=wdTabLeaderSpaces
agmorgan
Aug 25th, 2005, 06:23 PM
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
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 :ehh: :sick:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.