我正在尝试绘制一个非常简单的网络图。我的代码:
\begin{tikzpicture}
\node[draw, shape=circle] (v0) at (0,0) {$v_0$};
\node[draw, shape=circle] (v1) at (1,0) {$v_1$};
\node[rectangle,minimum width=6em,draw] (v3) at (0.5,-1) {$v_3$};
\draw [thick] (v0) -- (v1)
(v0) -- (v3)
(v1) -- (v3);
\end{tikzpicture}
我希望从上方两个节点开始的线直直地向下延伸到矩形的边缘。有没有简单的方法可以做到这一点?
答案1
是的 :-):
\documentclass[tikz,
border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw, shape=circle] (v0) at (0,0) {$v_0$};
\node[draw, shape=circle] (v1) at (1,0) {$v_1$};
\node[rectangle,minimum width=6em,draw] (v3) at (0.5,-1) {$v_3$};
\draw [thick] (v0) -- (v1)
(v0) -- (v0 |- v3.north) % <-- changed coordinates
(v1) -- (v1 |- v3.north); % <-- changed coordinates
\end{tikzpicture}
\end{document}
|-
意味着线条首先“垂直”延伸,然后“水平”延伸......确定垂直线和水平线(v0 |- v3.north)
交点的坐标。v0.center
v3.north