# Label an angle in xypic

I am frequently (i.e. about once per quarter, right before the end) set upon by the need to draw a diagram in which various lines are drawn and the angles between them labeled. I've been using xy-pic for my diagrams, and would like to continue, but in a small diagram, the right location for the name of the angle to appear doesn't correspond to any particular spot on the grid. Is there a nice way to do this?

I give an example of the sort of diagram I have in mind.

\documentclass{article}
\usepackage{xypic}
\begin{document}
\diagram
&&&&&*\\
&&*\ar[-1,3]\ar[-1,0]&&&\\
\enddiagram
\end{document}

-
please post a small compilable example. This code snippet did not compile even after I've built a document with xy-pic around it. –  Stefan Kottwitz Nov 30 '10 at 22:08
This version compiles. Apparently I have to comment out backslashes in regular text, but not in code, so it ended up with too many backslashes originally. –  Henry Nov 30 '10 at 22:19
Are you sure you want to use xy-pic for this? As far as I know that isn't what xy-pic is designed for. Using TikZ and polar coordinates this would be rather trivial. –  Caramdir Nov 30 '10 at 22:41
@Caramdir: I've never used TikZ, and I'm not thrilled about learning yet another new set of commands (though, as this question demonstrates, I never really learned xy-pic that well anyway). I'll look into that. –  Henry Nov 30 '10 at 22:45
I can understand that, as TikZ is rather huge. But it does have the advantage of having an extremely good manual and a very well-structured and readable syntax. –  Caramdir Nov 30 '10 at 22:50

An xy-pic solution: place an arrow label at the beginning of the arrow by ^<<{\beta}, use more or less > if required:

\diagram
&&&&&*\\
&&*\ar[-1,3]^<<{\beta}\ar[-1,0]&&&\\
\enddiagram


-
Just what I was looking for. Thanks. –  Henry Dec 1 '10 at 1:34

I know, you did specifically ask for an xy-pic solution. But I couldn't resist to answer with a TikZ solution (before Andrew does ;-)).

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
% define some nodes using the \node (name) at (coordinates) {content} syntax
\node (top) at (0,1) {};
\node (top-right) at (3,1) {$*$};
\node (bottom) at (0,0) {$*$};

% draw the arrows
\draw[->] (bottom) -- (top);
\draw[->] (bottom) -- (top-right);

\node at (45:0.6) {$72^\circ$};
\end{tikzpicture}
\end{document}


As you can see, the syntax is rather straightforward (though of course a lot more verbose than xy-pic). In theory, you could put those nodes into a matrix as in xy, but here there is really no need for that.

A slightly more fancy example in the same spirit (as I don't know what you actually plan to do)

\begin{tikzpicture}
\node (top) at (0,1.5) {};
\node (top-right) at (18:1.5) {};
\node (bottom) at (0,0) {};

\fill (bottom) circle (0.05);
\fill (top-right) circle (0.05);
\fill (top) circle (0.05);

\draw[->] (bottom) -- (top);
\draw[->] (bottom) -- (top-right);

\node at (45:0.6) {$72^\circ$};
\draw[->] (22:1) arc (22:86:1);
\end{tikzpicture}


-
Them's fightin' words. –  Andrew Stacey Dec 1 '10 at 12:48

I couldn't resist the challenge, sorry. Here's my version (using TikZ):

\documentclass{article}

\usepackage{tikz}

\begin{document}

\tikzset{point/.style={circle,fill,inner sep=2pt}}
\tikzset{vector/.style={shorten >=3pt, shorten <=4pt,-latex}}
\tikzset{angle/.style={bend right,shorten >=5pt, shorten <=5pt,->,gray}}

\begin{tikzpicture}
\def\angle{72}
\node[point] (origin) at (0,0) {};
\node[point] (yaxis) at (90:4) {};
\node[point] (avector) at (90 - \angle:4) {};

\draw[vector] (origin) -- coordinate (a) (yaxis);
\draw[vector] (origin) -- coordinate (b) (avector);

\draw[angle] (b) to node[auto,swap] {$$\angle^\circ$$} (a);
\end{tikzpicture}
\end{document}


The purpose of this example is to show how drawing diagrams with TikZ is very much like writing articles with LaTeX: the interface makes it very easy to separate content from style. I've created three "styles": one for points, one for vectors, and one for the angle bits. Then I place the points, using the "point" syntax and specifying using polar coordinates. Next, I draw the vectors between the origin and those points. I also "mark" the half-way point on each vector. Finally, I draw the arc between the "marks", using the "angle" style. Note also that I only need to specify the angle once. All the rest is computed from that.

It's not perfect - angles on the "other side" should have "bend left" rather than "bend right", but that's not hard to do. One could also replace the "to" by an arc if it gets too flat for angles near 180.

-