3

I have a TikZ code like below. As you can see in the second line in \foreach, I want the arrow placed below one by one. But it didn't work. I've tried to debug for a while, but have not fixed it.

\begin{tikzpicture}[scale = 0.6]
\foreach \n in {1,2,3,4,5}{
    \node[shape=circle,draw,inner sep=0.7](number \n) at (\n,0) {$a_\n$};
    \draw[|->,yshift=-\n cm](number 1.west) -- (number \n.east);
}
\node[inner sep=1] at (6,0) {$\cdots$};
\end{tikzpicture}

enter image description here

Should I write something like yshift=(-\n) cm to tell the engine for the precedence?

4

Here is one way to do it. You can yshift all you want, but (number \n) won't move.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale = 0.6]
\foreach \n in {1,2,3,4,5}{
    \node[shape=circle,draw,inner sep=0.7](number \n) at (\n,0) {$a_\n$};
    \coordinate (level \n) at (0,-\n);
    \draw[|->] (number 1.west |- level \n) -- (number \n.east |- level \n);
}
\node[inner sep=1] at (6,0) {$\cdots$};
\end{tikzpicture}
\end{document} 

enter image description here


It turns out you can apply yshift INSIDE the coordinate.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale = 0.6]
\foreach \n in {1,2,3,4,5}{
    \node[shape=circle,draw,inner sep=0.7](number \n) at (\n,0) {$a_\n$};
    \draw[|->] ([yshift=-\n cm] number 1.west) -- ([yshift=-\n cm] number \n.east);
}
\node[inner sep=1] at (6,0) {$\cdots$};
\end{tikzpicture}
\end{document} 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.