# [metapost] Positioning labels at a vertex

Dan Luecking luecking at uark.edu
Wed Nov 17 21:15:17 CET 2010

```At 09:16 AM 11/17/2010, Yasir Malik wrote:

>a = (0, 0);
>b = 5u*dir(40) + a;
>c = (0, 1u);
>d = (5u, 1u);
>
>draw a--b;
>draw c--d;
>
>v = (a--b) intersectionpoint (c--d);
>
>% the label intersects with a line using these two commands
>%label.llft(btex \$40^\circ\$ etex, v);
>%label.lft(btex \$40^\circ\$ etex, v);
>
>% this displays properly but it took at least 5 tries
>label(btex \$40^\circ\$ etex, v + (-.4u, -.15u));
>
>As I note in the comments, the label intersects with one of the
>lines using the first two label calls.  The third label looks right,
>but it was frustrating getting it right.  If I change the angle,
>I'll have to spend more time repositioning the label.

If you find you do really need to specify the location
of a label manually (as you do here to label the angle)
you should not use the scaling factor in the offset from v.

Changing u will change the position of v, but not the slopes
of the lines, nor the size of the label. Thus the offset
of the label from v should not change. Thus, I would do
something like the following:

label(btex \$40^\circ\$ etex, v - r*dir 20)

then adjust r by hand. Note that dir 20 is right down
the middle of the angle, which is probably where you
want to center a label which is not much wider than
it is tall. I started with an estimate of
r = <height of label>/sind 40
as r = 8pt/.7 or about 11, and then adjusted it up to
r = 12. A change in u doesn't require any change in
this value.

Regards,
Dan

Daniel H. Luecking
Department of Mathematical Sciences
Fayetteville, Arkansas
http://www-cs-faculty.stanford.edu/~knuth/iaq.html

```