5
\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?

enter image description here

4

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

Output

  • Do you know why the node didn't work with .center? – dustin 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. – remjg Apr 14 '14 at 21:07

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.