以下代码块包含一个最小工作示例。第一个 TikZ 绘图未使用明确定义的节点。第二个 TikZ 绘图使用明确定义的节点。
我以为这两幅图会产生相同的结果,因为两幅图中的节点都没有标签。但是,我注意到边的长度不同。(见下图)。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\draw[->] (0,0.2) -- (1,0.2);
\draw[->] (0,0.4) -- (1,0.4);
\end{tikzpicture}
\begin{tikzpicture}
\node (start1) at (0,0) {};
\node (end1) at (1,0) {};
\node (start2) at (0,0.2) {};
\node (end2) at (1,0.2) {};
\node (start3) at (0,0.4) {};
\node (end3) at (1,0.4) {};
\draw[->] (start1) -- (end1);
\draw[->] (start2) -- (end2);
\draw[->] (start3) -- (end3);
\end{tikzpicture}
\end{document}
\end{document}
答案1
也许你想要的coordinates
不是nodes
。节点即使为空也有一个大小(除非你选择箭头的原点到锚点,即你锚定节点本身的位置的对立面)
请参阅以下 MWE coordinates
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\draw[->] (0,0.2) -- (1,0.2);
\draw[->] (0,0.4) -- (1,0.4);
\end{tikzpicture}
\vspace{2ex}
\begin{tikzpicture}
\coordinate (start1) at (0,0);
\coordinate (end1) at (1,0);
\coordinate (start2) at (0,0.2);
\coordinate (end2) at (1,0.2);
\coordinate (start3) at (0,0.4);
\coordinate (end3) at (1,0.4);
\draw[->] (start1) -- (end1);
\draw[->] (start2) -- (end2);
\draw[->] (start3) -- (end3);
\end{tikzpicture}
\end{document}
答案2
这只是为了说明@Mane32 所说的节点和锚点的大小。
在左侧,该选项draw
使节点的轮廓可见。如您所见,箭头从节点的边界开始并终止。
在右侧,箭头从center
节点的锚点开始并终止。现在箭头的长度与显式\draw
命令的长度相同。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\draw[->] (0,0.2) -- (1,0.2);
\draw[->] (0,0.4) -- (1,0.4);
\begin{scope}[yshift=-6mm]
\node[draw] (start1) at (0,0) {};
\node[draw] (end1) at (1,0) {};
\node[draw] (start2) at (0,0.2) {};
\node[draw] (end2) at (1,0.2) {};
\node[draw] (start3) at (0,0.4) {};
\node[draw] (end3) at (1,0.4) {};
\draw[->] (start1) -- (end1);
\draw[->] (start2) -- (end2);
\draw[->] (start3) -- (end3);
\end{scope}
\end{tikzpicture}
\quad
\begin{tikzpicture}
\draw[->] (0,0) -- (1,0);
\draw[->] (0,0.2) -- (1,0.2);
\draw[->] (0,0.4) -- (1,0.4);
\begin{scope}[yshift=-6mm]
\node[draw] (start1) at (0,0) {};
\node[draw] (end1) at (1,0) {};
\node[draw] (start2) at (0,0.2) {};
\node[draw] (end2) at (1,0.2) {};
\node[draw] (start3) at (0,0.4) {};
\node[draw] (end3) at (1,0.4) {};
\draw[->] (start1.center) -- (end1.center);
\draw[->] (start2.center) -- (end2.center);
\draw[->] (start3.center) -- (end3.center);
\end{scope}
\end{tikzpicture}
\end{document}