How to align text left, center, right?

L

LurfysMa

I have 3 fields in the footer of a template (name, title, date). The
date is a date field. The name and title are custom document
variables.

I would like all 3 on the same line in the footer with the name left
justified, the date right justified, and the title centered in the
remaining space. The name may be short or quite long. Same with the
title. Some examples:

nnnnnnnn tttttttttt mm/dd/yy
nnnnnnnnnnnnnnnnnnnnn ttttt mm/dd/yy
nnnnnnn ttttttttttttttttttt mm/dd/yy

Is there a way to do that?

The document has 7-8 sections each with a different footer.

What I have been doing is defining two tabs: one at the right margin
and one about in the center. Then, after I set the document variables,
I manually edit the footers in each section and adjust the center tab.

Is there a way to do that automatically?

Thanks
 
D

Doug Robbins - Word MVP

Not with a variable pitch font.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Suzanne S. Barnhill

There's a way to do this, but it's a bit finicking:

1. Format the paragraph as Justified.

2. Type the name. Use nonbreaking spaces between words. Follow the name with
an ordinary space.

3. Type the title, again using nonbreaking spaces internally and an ordinary
space at the end.

4. Type the date, again using nonbreaking spaces (if any).

5. Press Shift+Enter.

6. If the blank line thus produced causes a problem, select just the
paragraph mark and format it as 1 point or Hidden.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
L

LurfysMa

Not with a variable pitch font.

I infer that you are talking about a macro that could count the
characters in the 3 fields and then divide the remaining soace
equally, right?

Not that I'm going to do this, but isn't there some VBA command that
willr eturn the width of a text string in a given font and size?
 
L

LurfysMa

There's a way to do this, but it's a bit finicking:

1. Format the paragraph as Justified.

2. Type the name. Use nonbreaking spaces between words. Follow the name with
an ordinary space.

3. Type the title, again using nonbreaking spaces internally and an ordinary
space at the end.

4. Type the date, again using nonbreaking spaces (if any).

5. Press Shift+Enter.

6. If the blank line thus produced causes a problem, select just the
paragraph mark and format it as 1 point or Hidden.

Now that's a clever solution. I'll fiddle around with it.

Back in the "old days" on IBM mainframes, we used to have a word
processor that has a "Split" command. You could enter two or more text
strings separated by delimiters and the program would divide the
available space evenly. This was a markup program (not wysiwyg) so we
would imbed controls:

..foot on
..space 2
..split /String one/String two/String three/String four/
..foot off

We used that one a lot.
 
J

Jay Freedman

I infer that you are talking about a macro that could count the
characters in the 3 fields and then divide the remaining soace
equally, right?

Not that I'm going to do this, but isn't there some VBA command that
willr eturn the width of a text string in a given font and size?

For the record, no, VBA doesn't have any "how wide is this string"
function that doesn't require inserting the string first. Its big
brother VB does, as do the heavy-duty languages like C++ and C#, but
VBA has always been without it. Where it is available, it's a fairly
complicated procedure -- you have to get a graphic context (a memory
area loaded with the properties of the current printer), create a font
object, pass the string and the font object to the function and get
back a width in pixels, convert that to the rendering width on the
page, and finally release the font and context objects.

The closest you can get in VBA is to insert the string in the document
and then call
Selection.Information(wdHorizontalPositionRelativeToTextBoundary),
which returns the position of the cursor in points from the left
margin.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
D

Doug Robbins - Word MVP

And in those days, you used fixed width fonts and you knew exactly how many
characters fitted onto one line.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LurfysMa

And in those days, you used fixed width fonts and you knew exactly how many
characters fitted onto one line.

You may be right. It's been so long. But I think we did have
proportional space fonts as well.

In any case, it would not be much harder for the word processor to do
the "split" function with proportional space fonts than monospace. The
work processor has to know "exactly how many characters will fit on a
line" regardless.
 
G

Graham Mayor

Not so - each character will have a different width eg the letter i takes up
less space than the letter w.

iiiiiiiiii
wwwwwwwwww

The line wrap is set by a variety of factors not least of which is the
current printer driver.

Why make things unnecessarily difficult for yourself? Put a centre aligned
tab at the centre of the page
and a right aligned tab at the right margin. The texts will align to the
page.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

LurfysMa

Not so - each character will have a different width eg the letter i takes up
less space than the letter w.

Of course. That's why it's a proportional font.

But each character of each font includes information on its width. The
WP knows how wide the line is and it knows how wide each character is
and it can add and subtract. Nothing more is needed. If this weren't
so, the WP would not be able to format lines.

So, to do my split function, all that is needed is for the WP to add
up the widths of the three text strings, subtract that from the line
length, and divide by 2.
iiiiiiiiii
wwwwwwwwww

The line wrap is set by a variety of factors not least of which is the
current printer driver.

Why make things unnecessarily difficult for yourself? Put a centre aligned
tab at the centre of the page
and a right aligned tab at the right margin. The texts will align to the
page.

That won't work. The left and center strings can be very short or very
wide. That's the whole problem. The left string can be wider than half
the line width. I don't want the middle string centered on the line
width, I want it centered on the space between the right edge of te
left string and the left edge of the right string.
 
B

Bob S

One scheme that might work, or at least be marginally easier, is to
use a one-row three-column table in the footer.

Make the table width 100% and turn off borders.

Put in your field codes.

Make the left column left aligned, drag the width small, and turn off
text wrapping.

Make the center column center aligned.

Make the right column right aligned, drag the width small, and turn
off text wrapping.

If you are really lucky, when you later evaluate the fields the left
and right table columns will expand to fit their contents and
everything will work like magic. If you are less lucky at least you
will only have to drag the column edges to make the left and right
cells minimum size for their contents, which might be easier than
trying to position the center tab stop.

Bob S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top