# TikZ: issue with lines in foreach loop

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (h) at (0, 3);
\coordinate (O) at (0, 0);

\draw (O) -- +(-3, 0);
\draw[-latex] (O) -- +(3, 0) node[right, font = \scriptsize] {$x$};
\draw[-latex] (O) -- +(0, 4) node[above, font = \scriptsize] {$z$};

\foreach \x/\s in {-1.5/{-}, 1.5/{+}}{
\draw (\x, 0) -- +(0, -0.1) node[below, font = \scriptsize] (l\s) at
(\x, 0) {$\s\frac{\ell}{2}$};
}

\draw (l-.center) -- (h);
\draw (l+.center) -- (h);
\end{tikzpicture}
\end{document}


My final two line are drawing from the labels not the x intercept line where I would anticipate. How can this be correct?

## 1 Answer

You can use coordinate inside a path to name the exact coordinates. You were naming the node below the desired coordinates.

## Code

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (h) at (0, 3);
\coordinate (O) at (0, 0);

\draw (O) -- +(-3, 0);
\draw[-latex] (O) -- +(3, 0) node[right, font = \scriptsize] {$x$};
\draw[-latex] (O) -- +(0, 4) node[above, font = \scriptsize] {$z$};

\foreach \x/\s in {-1.5/{-}, 1.5/{+}}{
\draw (\x, 0) coordinate (l\s) -- +(0, -0.1) node[below, font = \scriptsize] at
(\x, 0) {$\s\frac{\ell}{2}$};
}

\draw (l-.center) -- (h);
\draw (l+.center) -- (h);
\end{tikzpicture}
\end{document}


## Output

• Do you know why the node didn't work with .center? Apr 14 '14 at 20:59
• You should try .north for the desire result. It also works. .center refers to the center of the node with text. Since the node is place below, it is expected that the line will go "below" the axis too. Apr 14 '14 at 21:07