我对 Tikz 还比较陌生,正在尝试绘制一个带有线条的图表。这是我的 MWE
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\[
\begin{tikzpicture}
\draw (0,0.9) -- (3.0,0.9) -- (3.0,-0.9) -- (0,-0.9) -- (0,0.9);
\draw (1.0,-0.9) -- (1.0,0.9);
\draw (2.0,-0.9) -- (2.0,0.9);
\path (1.1,0.6) node (p9) {};
\path (1.1,0.2) node (p10) {};
\path (1.1,-0.2) node (p11) {};
\path (1.1,-0.6) node (p12) {};
\path (1.9,0.6) node (p13) {};
\path (1.9,0.2) node (p14) {};
\path (1.9,-0.2) node (p15) {};
\path (1.9,-0.6) node (p16) {};
\path (2.1,0.6) node (p17) {};
\path (2.1,0.2) node (p18) {};
\path (2.1,-0.2) node (p19) {};
\path (2.1,-0.6) node (p20) {};
\path (2.9,0.6) node (p21) {};
\path (2.9,0.2) node (p22) {};
\path (2.9,-0.2) node (p23) {};
\path (2.9,-0.6) node (p24) {};
\draw (p9) to [bend left=10] (p17);
\draw (p10) to [bend left=10] (p18);
\draw (p11) to [bend left=10] (p19);
\draw (p12) to [bend left=10] (p20);
\draw (p13) to [bend right=10] (p21);
\draw (p14) to [bend right=10] (p22);
\draw (p15) to [bend right=10] (p23);
\draw (p16) to [bend right=10] (p24);
\end{tikzpicture}
\]
\end{document}
输出结果如下
有人能解释为什么曲线似乎没有击中正确的节点吗?
编辑:为了澄清情况,问题在于为什么这些线似乎没有到达相关节点的中心。以下答案已解决此问题。
答案1
曲线与节点相交,但即使是空节点也有宽度和高度。为了说明这一点,绘制了第二张图中的节点。也许您想定义coordinate
s 而不是node
像第三张图中那样定义 s:
代码:
\documentclass[margin=5mm,tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
green!40!black,
colored/.style={fill=#1!20,draw=#1!50!black!50}
]
\draw[help lines, step=0.5] (0,0)grid(2,1);
\path (0.5,0.5) node (p1) {};
\path (1,0.5) node (p2) {};
\draw (p1) to [bend left=10] (p2);
%
\begin{scope}[yshift=-1.1cm]
\draw[help lines, step=0.5] (0,0)grid(2,1);
\path (0.5,0.5) node[colored=red] (p3) {};
\path (1,0.5) node[colored=blue] (p4) {};
\draw (p3) to [bend left=10] (p4);
\end{scope}
\draw[dotted](p1.east)--(p3.east)(p2.west)--(p4.west);
%
\begin{scope}[yshift=-2.2cm]
\draw[help lines, step=0.5] (0,0)grid(2,1);
\path (0.5,0.5) coordinate (p5);
\path (1,0.5) coordinate (p6);
\draw (p5) to [bend left=10] (p6);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
没有理由将您的 tikz 图片放在显示的数学环境中(即删除括号 \[ \])。
当您使用“to”时,tikz 将绘制一条连接到节点外部边界的边(未在图片中绘制但仍在计算)比较:
\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw](x){};
\node[draw](y) at (2cm,0){};
\draw (x) to [bend left=10] (y);
\draw[red] (x.center) to [bend right=10] (y.center);
\end{tikzpicture}
\end{document}
PS:请尝试实际制作一个最小工作示例,并更精确地说明问题是什么。我不确定我是否理解了你在问什么。;)
答案3
我同意 @Echsecutor 的评论,不清楚你想要的结果是什么。为了用你的例子来说明那个发帖人的观点,看看根据你指定终点的方式绘制线条的不同。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\[
\begin{tikzpicture}
\draw (0,0.9) -- (3.0,0.9) -- (3.0,-0.9) -- (0,-0.9) -- (0,0.9);
\draw (1.0,-0.9) -- (1.0,0.9);
\draw (2.0,-0.9) -- (2.0,0.9);
\path (1.1,0.6) node (p9) {};
\path (1.1,0.2) node (p10) {};
\path (1.1,-0.2) node (p11) {};
\path (1.1,-0.6) node (p12) {};
\path (1.9,0.6) node (p13) {};
\path (1.9,0.2) node (p14) {};
\path (1.9,-0.2) node (p15) {};
\path (1.9,-0.6) node (p16) {};
\path (2.1,0.6) node (p17) {};
\path (2.1,0.2) node (p18) {};
\path (2.1,-0.2) node (p19) {};
\path (2.1,-0.6) node (p20) {};
\path (2.9,0.6) node (p21) {};
\path (2.9,0.2) node (p22) {};
\path (2.9,-0.2) node (p23) {};
\path (2.9,-0.6) node (p24) {};
\draw (p9) to [bend left=10] (p17.center);
\draw (p10) to [bend left=10] (p18.west);
\draw (p11) to [bend left=10] (p19.east);
\draw (p12) to [bend left=10] (p20);
\draw (p13) to [bend right=10] (p21);
\draw (p14) to [bend right=10] (p22);
\draw (p15) to [bend right=10] (p23);
\draw (p16) to [bend right=10] (p24);
\end{tikzpicture}
\]
\end{document}
有结果