# Positioning Labels in Asymptote

How can I control the position of the $x$ label below? Created with draw("$x$",O--X,blue,Arrow3)

I know I can manually control label positions with label("$x$",<position>,blue), but is there a more automatic way---something analogous to the tikz options node[near end] or node[midway, above].

\documentclass{article}
\usepackage{asymptote}

\begin{document}

\begin{asy}[width=0.5\textwidth]
import graph3;
import grid3;
currentprojection=perspective(-0.51,3,1,up=Z);

draw("$x$",O--X,blue,Arrow3);
draw(O--Y,green,Arrow3);
draw(O--Z,red,Arrow3);
\end{asy}

\end{document}


• You can use point(path,p) to make it slightly more automatic. eg label("$x$",align=N,point(O--X,0.8)); – Thruston Feb 14 '14 at 15:34

Pass a Label object to draw() instead of a simple string. The Label() constructor takes options (among others) position and align. In particular, passing it the option position=Relative(0.2), for instance, instructs Asymptote to draw the label 20% of the way along the path.

\documentclass[margin=10pt]{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}[width=0.5\textwidth]
settings.render=4;
settings.prc=false;
import three;
currentprojection=perspective(-0.51,3,1,up=Z);

draw(L=Label("$x$", position=Relative(0.8), align=N), O--X, blue, Arrow3);
draw(O--Y,green,Arrow3);
draw(O--Z,red,Arrow3);
\end{asy}
\end{document}


• Great! Just curious: Why might it be useful to name the label L? Why might you refer to it later? – Chris Chudzicki Feb 14 '14 at 17:44
• I'm not naming the label; I'm using key-value syntax. This frees me from having to remember the order of the arguments of the draw() command. In particular, in my own code, I almost always put the path as the first argument. – Charles Staats Feb 14 '14 at 18:13