\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}
我的最后两条线是根据标签绘制的,而不是我预期的 x 截距线。这怎么可能正确呢?
答案1
您可以coordinate
在路径内使用来命名精确的坐标。您正在命名节点以下所需的坐标。
代码
\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}