使曲线路径相对于 TikZ 节点看起来平行

使曲线路径相对于 TikZ 节点看起来平行

我有一张如下的图表:

在此处输入图片描述

我已经水平对齐了节点bc相对于它们的中心,但是z由于它不再对称,这会导致弯曲路径出现问题。

如何使路径的两端z彼此平行,并且标签与节点对齐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.westz.eastz.eastc.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}

结果变体角

相关内容