dcarson@cisunx.UUCP (David Carson) (03/14/89)
I need a little simple advice on alignment. I'm trying to make a letterhead where the address appears on the right side of the page, but is not right- justified. It should be left justified so that the longest line of the address is flush with the right margin, like so: John Doe | 1600 Pennsylvania Ave| Washington, D.C. | 20002 | margin^ First I tried using \halign without success. Then I managed, I think, to get it with the following: \settabs\+\hskip<dimen known larger than required> plus<some> minus<some>&\cr and then setting the lines with a tab: \+&<text>\cr This does not seem very elegant, and I'm not totally convinced that it works perfectly. One problem I am trying to avoid is the subtle problem of TeX pushing the lines (still left-justified) past the margin, without calling it an overfull box (this happened before I added "plus<some> minus<some>"). Is there a way in TeX to measure text? Then I could do something like: \dimen1=\hsize \advance\dimen1 by-\measure<longest line of addr> %subtract the length of text \settabs\+\hskip<\dimen1>&\cr If this question warrants an answer on the net, answer me there. Otherwise, just send me e-mail. Thank you. David Carson Internet: dcarson@unix.cis.pittsburgh.edu Bitnet: dcarson@PITTVMS
mc3i+@andrew.cmu.edu (Martin Costabel) (03/14/89)
> *Excerpts from ext.nn.comp.text: 13-Mar-89 tabstop according to longes..* > *David Carson@cisunx.UUCP (1339)* > I need a little simple advice on alignment. I'm trying to make a letterhead > where the address appears on the right side of the page, but is not right- > justified. It should be left justified so that the longest line of the > address is flush with the right margin, like so: > John Doe | > 1600 Pennsylvania Ave| > Washington, D.C. | > 20002 | > margin^ [Unsatisfactory solutions deleted] Shortest answer: Use the LaTeX letter style. From letter.sty one finds the explicit LaTeX solution: {\raggedleft \begin{tabular}{l}\ignorespaces John Doe\\ 1600 Pennsylvania Ave\\ Washington, D.C.\\ 20002 \end{tabular}\par} A corresponding Plain TeX solution would be {\leftskip 0pt plus 1fill \parskip 0pt \def\\{\egroup\par\hbox\bgroup} \leavevmode \hbox{\vbox{{\\ John Doe\\ 1600 Pennsylvania Ave\\ Washington, D.C.\\ 20002 }}}\par} This solution leaves the computation of lengths of lines to TeX. --Martin Costabel
gm@romeo.cs.duke.edu (Greg McGary) (03/17/89)
In article <16709@cisunx.UUCP> dcarson@cisunx.UUCP (David Carson) writes: >I need a little simple advice on alignment. I'm trying to make a letterhead >where the address appears on the right side of the page, but is not right- >justified. It should be left justified so that the longest line of the >address is flush with the right margin, like so: > > John Doe | > 1600 Pennsylvania Ave| > Washington, D.C. | > 20002 | > margin^ > >First I tried using \halign without success. In order to get \halign to work the way you want, you need to be sure to use \halign to\hsize{...} so that the table will be as wide as the page, then you need to be sure that the tabskip glue will stretch. This works: \tabskip=0pt plus1fill \halign to\hsize{#\hfil\tabskip=0pt\cr John Doe\cr 1600 Pennsylvania Ave.\cr Washington, D.C.\cr 20002\cr} Notice that the stretchy tabskip glue before the first column has a higher order of infinity than the \hfil that right-justifies the column. I like to do letterheads that are a little fancier. One of mine looks like this: (919) 490-6037 Greg McGary (919) 493-5953 (FAX) --------------------------------------------------------------------- Suite 102 4201 University Drive Durham, NC 27707 I do it like this: \font\rmX=cmr10 \font\biXIV=cmti10 at 14.4pt \baselineskip=12pt\rmX \ialign to \hsize{#\hfil\tabskip=0pt plus1fill&\tabskip=0pt#\hfil\cr & (919) 490-6037\cr \biXIV Greg McGary & (919) 493-5953 (FAX)\cr \noalign{\vskip4pt\hrule\vskip4pt} & Suite 102\cr & 4201 University Drive\cr & Durham, North Carolina~~27707\cr} The two phone numbers in cmr10 have the proper interline spacing no matter how tall the font used for the name happens to be. >Is there a way in TeX to measure text? Then I could do something like: > >\dimen1=\hsize >\advance\dimen1 by-\measure<longest line of addr> %subtract the length of text >\settabs\+\hskip<\dimen1>&\cr Sure, put the text into a box then use one of several box-metric primitives: \setbox0=\hbox{<longest line of addr>} Now, \wd0 gives the box's width \ht0 gives the box's height \dp0 gives the box's depth. -- Greg McGary -- 4201 University Drive #102, Durham, NC 27707 voice: (919) 490-6037 -- {decvax,hplabs,seismo,mcnc}!duke!gm data: (919) 493-5953 -- gm@cs.duke.edu