我想绘制一条连接多个节点的边。我可以使用“到”功能来实现这一点,如下例所示:
\documentclass[convert={density=300,size=1080x800,outext=.png}]{ standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\matrix (m)[column sep=.5in, row sep=.5in, ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {}; \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {}; \\
};
\draw (r1c1) to[<-] (r2c1.center) to (r2c2.center) to (r1c2);
\end{tikzpicture}
\end{document}
输出如下:
我无法更改单个段或连接器的属性。例如,tikz 放弃了在连接的第一条腿上放置箭头的指令。我首先想要实现的是圆角。
为了跟进这一点,以下是通过多个节点实现边缘的三种方法
\documentclass[convert={density=300,size=1080x800,outext=.png{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\matrix (m)[column sep=.5in, row sep=.5in, ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {}; \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {}; \\
};
\draw (r1c1) edge (r2c1.center) edge (r2c2.center) edge (r1c2);
\end{tikzpicture}
\begin{tikzpicture}
\matrix (m)[column sep=.5in, row sep=.5in, ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {}; \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {}; \\
};
\draw (r1c1) -- (r2c1.center) -- (r2c2.center) -- (r1c2);
\end{tikzpicture}
\end{document}
其输出如下:
使用边缘不起作用,但却是最灵活的。
答案1
像这样?
\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\matrix (m) [column sep=.5in, row sep=.5in, ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {}; \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {}; \\
};
\draw[rounded corners,<-] (r1c1) |- (r2c2.center) -- (r1c2);
\end{tikzpicture}
\end{document}
附录:
中的节点功能matrix
不太清楚。仅考虑曲线,可以使用以下方法获得相同的结果:
\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes, nodes in empty cells,
column sep=.5in, row sep=.5in]
{
& & \\
& & \\
};
\draw[rounded corners,<-] (m-1-1) |- (m-2-2.center) -- (m-1-2);
\end{tikzpicture}
\end{document}