Ich habe ein Diagramm, das so aussieht:
Ich habe Knoten horizontal b
und c
in Bezug auf ihre Mittelpunkte ausgerichtet, aber dies verursacht ein Problem mit dem gekrümmten Pfad, z
da dieser nicht mehr symmetrisch ist.
Wie kann ich dafür sorgen, dass die Enden des Pfads z
parallel zueinander verlaufen und die Beschriftung mit dem Knoten übereinstimmt ( a
wie im Diagramm unten), während gleichzeitig die b
mittige c
Ausrichtung beibehalten wird?
Code:
\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}
Antwort1
Das folgende Beispiel platziert zuerst den Knoten z
für „z“ links von Knoten , a
um „z“ auf die gleiche Grundlinie wie „a“ zu bringen. Dann wird die Kurve in zwei Teile geteilt, vom Knoten b.west
zu z.east
und z.east
zu c.west
. Die Komponenten .west
und .east
sorgen für die richtigen Start- und Endpunkte. Die Start- und Endwinkel der Kurventeile werden durch Optionen in
und out
für den Pfadoperator angegeben to
. Dies erfordert die Bibliothek topaths
:
\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}
Und eine Variante, bei der die geraden Verbindungen (a) -- (b)
an (a) -- (c)
den Ecken verbunden werden. In diesem Fall sieht es vielleicht besser aus.
\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}