使彎曲路徑相對於 TikZ 節點顯得平行

使彎曲路徑相對於 TikZ 節點顯得平行

我有一個如下所示的圖表:

在此輸入影像描述

我有水平對齊的節點b及其c中心,但這會導致彎曲路徑出現問題,z因為它不再對稱。

如何使路徑的兩端z彼此平行並且標籤與 node 對齊a(如下圖所示),同時仍保持居中b對齊c

在此輸入影像描述

代碼:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[auto,node distance=2cm, align=center,
block/.style={rectangle,draw, thick,inner sep=2pt,minimum size=10mm},
paths/.style={->, very thick, >=stealth'},
curve/.style={<->, thick, >=stealth', bend left=270, looseness=2, distance = 60mm},
]

%Draw, place, and label variables
\node [block] (a) {a};
\node [block] (b) [above right=of a] {bbbbbbbbbb};
\node [block] (c) [below= 4cm of b.south, anchor = north] {ccc};
%\node [block] (c) [below right= of a] {ccc}; % ideal curved path between b and c here, but block not centered

% Draw paths and label them
\draw [paths] (a) to node {x} (b);
\draw [paths] (a) to node [swap] {y} (c);
\draw [curve] (b) to node [swap,midway] {z} (c);
\end{tikzpicture}
\end{document}

答案1

以下範例首先將z「z」的節點放置在節點的左側,a以使「z」與「a」處於同一基線。然後曲線被分成兩部分,從節點b.westtoz.eastz.eastto c.west.west並確保組件.east有正確的起點和終點。曲線部分的起始角度和結束角度由路徑運算子的選項in和指定。這需要庫:outtotopaths

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc,topaths}
\begin{document}
\begin{tikzpicture}[auto,node distance=2cm, align=center,
  block/.style={rectangle,draw, thick,inner sep=2pt,minimum size=10mm},
  paths/.style={->, very thick, >=stealth'},
  curve/.style={<->, thick, >=stealth'},
]

%Draw, place, and label variables
\node [block] (a) {a};
\node [block] (b) [above right=of a] {bbbbbbbbbb};
\node [block] (c) [below= 4cm of b.south, anchor = north] {ccc};
%\node [block] (c) [below right= of a] {ccc}; % ideal curved path between b
%and c here, but block not centered

% Draw paths and label them
\draw [paths] (a) to node {x} (b);
\draw [paths] (a) to node [swap] {y} (c);
\node [xshift=-3em, anchor=base east] (z) at (a.base west) {z};
\draw [curve] (b.west) to[out=180, in=90] (z.east)
                  to[out=-90, in=180] (c.west);
\end{tikzpicture}
\end{document}

結果

還有一個變體,其中直線連接(a) -- (b)(a) -- (c)在拐角處連接。在這種情況下,它可能看起來更好。

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc,topaths}
\begin{document}
\begin{tikzpicture}[auto,node distance=2cm, align=center,
  block/.style={rectangle,draw, thick,inner sep=2pt,minimum size=10mm},
  paths/.style={->, very thick, >=stealth'},
  curve/.style={<->, thick, >=stealth'},
]

%Draw, place, and label variables
\node [block] (a) {a};
\node [block] (b) [above right=of a] {bbbbbbbbbb};
\node [block] (c) [below= 4cm of b.south, anchor = north] {ccc};
%\node [block] (c) [below right= of a] {ccc}; % ideal curved path between b
%and c here, but block not centered

% Draw paths and label them
\draw [
  paths,
  shorten <=-.7\pgflinewidth,
] (a.north east) to node {x} (b.south west);
\draw [
  paths,
  shorten <=-.7\pgflinewidth,
] (a.south east) to node [swap] {y} (c.north west);
\node [xshift=-3em, anchor=base east] (z) at (a.base west) {z};
\draw [curve] (b.west) to[out=180, in=90] (z.east)
                  to[out=-90, in=180] (c.west);
\end{tikzpicture}
\end{document}

結果變體角點

相關內容