Annotate drawing produced by TikZ turtle
You could say node[above,xshift=-4em]
, where 4em
is half the turtle/distance
. Or you could do the same without turtle
. Now with named nodes.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{turtle}
\def\xs{1,2,3}
\begin{document}
\begin{tikzpicture}[turtle/distance=8em]
\draw [thick,turtle={home,right}]
\foreach \i in \xs
{
[turtle={forward,left}] node[above,xshift=-4em] (n\i) {\i}
[turtle={forward,right}]
};
\draw [red,-stealth] (n1) to[out=90,in=135] (n2);
\draw [red,-stealth] (n2) to[out=90,in=135] (n3);
\end{tikzpicture}
\begin{tikzpicture}[x=8em,y=8em]
\draw [thick] (0,0)
\foreach \i in \xs
{
-| node[above,pos=0.25] (n\i) {\i} (\i,\i)
};
\draw [red,-stealth] (n1) to[out=90,in=135] (n2);
\draw [red,-stealth] (n2) to[out=90,in=135] (n3);
\end{tikzpicture}
\end{document}
I did it a bit differently and put the directions in \xs
instead of just numbers. Then you can set coordinates at each end of a line (yellow circles below). These can be used to label the lines (green circles below). BTW, you should use standalone
instead of minimal
.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{turtle,calc}
\begin{document}
\def\xs{right,left,right,left,right,left,right,left,left,,left,right,left,right,left}
\begin{tikzpicture}[turtle/distance=8em]
\draw [thick][turtle={home}]coordinate(pos0)
\foreach \dir [count=\ind] in \xs {
[turtle={\dir,forward}]coordinate(pos\ind)
};
%% yellow circles; number the end points
\node[draw,circle,fill=yellow] at (pos0){0};
\foreach \dir [count=\ind] in \xs {
\node[draw,circle,fill=yellow] at (pos\ind){\ind};
}
%% green circles; number the paths
\foreach \dir [count=\ind,evaluate=\ind as \indminus using int(\ind-1)] in \xs {
\node[draw,circle,fill=green] at ($(pos\indminus)!0.5!(pos\ind)$){\indminus};
}
\end{tikzpicture}
\end{document}