![在 \draw[->] 上透過 tikz 更好地使用圓角](https://rvso.com/image/392369/%E5%9C%A8%20%5Cdraw%5B-%3E%5D%20%E4%B8%8A%E9%80%8F%E9%81%8E%20tikz%20%E6%9B%B4%E5%A5%BD%E5%9C%B0%E4%BD%BF%E7%94%A8%E5%9C%93%E8%A7%92.png)
我有這個代碼:
% !TeX encoding = UTF-8
\documentclass[utf8]{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\newcommand{\multilinks}[3]{\foreach \noeud in {#1} {\draw[<-, rounded corners] (#2.west) -| ++(-#3em,0em) |- (\noeud.east);}}
\begin{document}
\begin{figure}[htp]
\centering
\tikzset{
basic/.style={draw, rounded corners=2pt, thick, text width=8em, align=flush center, node distance=2em},
}
\begin{tikzpicture}[]
\matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
\node(n1){Text}; & \node(n3){another text}; \\
\node(n2){one thing}; & \node(n4){again text}; \\
};
\multilinks{n1,n2}{n3}{3}
\multilinks{n1}{n4}{1}
\end{tikzpicture}
\end{figure}
\end{document}
它給了我這個結果:
正如你所看到的,曲線很奇怪。我該如何修復它?
這是我想要的結果:
答案1
第一個的定義\multilinks
和列表略有變化:#1
\multilinks
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,positioning}
\newcommand{\multilinks}[3]{
\foreach \noeud in {#1} {
\draw[<-, rounded corners] (#2.west) -- ++(-#3 em,0em) |- (\noeud.east);
}
}
\begin{document}
\tikzset{
basic/.style={
draw,
rounded corners=2pt,
thick,
text width=8em,
align=flush center,
node distance=2em
}
}
\begin{tikzpicture}[]
\fontsize{8}{9} \selectfont
\matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
\node(n1){Text}; & \node(n3){another text}; \\
\node(n2){one thing}; & \node(n4){again text}; \\
};
\multilinks{n2}{n3}{3}
\multilinks{n1}{n4}{1}
\end{tikzpicture}
\end{document}
編輯
如果你想保持原來的方式, 的定義\multilinks
有點複雜:
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,positioning}
\newcommand{\multilinks}[3]{
\begin{scope}[x=1em,y=1em]
\newdimen\xend
\newdimen\yend
\path (#2.west);
\pgfgetlastxy{\xend}{\yend}
\foreach \i in {#1} {
\newdimen\xstart
\newdimen\ystart
\path (\i.east);
\pgfgetlastxy{\xstart}{\ystart}
\coordinate (1) at ({\xend-#3 em},\ystart);
\coordinate (2) at ({\xend-#3 em},\yend);
\ifdim\ystart=\yend
\draw[->] (\i.east)--(#2.west);
\else
\draw[->,rounded corners] (\i.east)--(1)--(2)--(#2.west);
\fi
}
\end{scope}
}
\begin{document}
\tikzset{
basic/.style={
draw,
rounded corners=2pt,
thick,
text width=8em,
align=flush center,
node distance=2em
}
}
\begin{tikzpicture}[]
\fontsize{8}{9} \selectfont
\matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
\node(n1){Text}; & \node(n3){another text}; \\
\node(n2){one thing}; & \node(n4){again text}; \\
};
\multilinks{n1,n2}{n3}{3}
\multilinks{n1}{n4}{1}
\end{tikzpicture}
\end{document}
我們必須添加一個,\ifdim
因為 Tikrounded corners
當 Z 被命令從點繪製路徑時,它非常困惑A指向A(即兩個相同的點):
\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[y=0.2cm]
\draw[rounded corners] (0,0) --(1,0) --(1,0)--(2,0) ; % Some bugs?
\draw[rounded corners] (0,-1)--(1,-1)-- (2,-1);
\draw[rounded corners] (0,-2)-- (2,-2);
\end{tikzpicture}
\end{document}