6

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}

enter image description here

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

1 Answer 1

9

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}

enter image description here

2
  • Great! Just curious: Why might it be useful to name the label L? Why might you refer to it later? Commented Feb 14, 2014 at 17:44
  • 2
    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. Commented Feb 14, 2014 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .