Tengo un diagrama que se parece a este:
Tengo nodos alineados horizontalmente b
y c
con respecto a sus centros, pero esto causa un problema con el camino curvo z
debido a que ya no es simétrico.
¿Cómo puedo hacer que los extremos del camino z
sean paralelos entre sí y que la etiqueta se alinee con el nodo a
, como en el diagrama a continuación, sin dejar de b
estar c
alineado centralmente?
Código:
\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}
Respuesta1
En el siguiente ejemplo, primero se coloca el nodo z
de "z" a la izquierda del nodo a
para obtener "z" en la misma línea base que "a". Luego, la curva se divide en dos partes, desde el nodo b.west
hacia z.east
y z.east
hacia c.west
. Los componentes .west
y .east
aseguran los puntos de inicio y finalización correctos. Los ángulos inicial y final de las partes de la curva se especifican mediante opciones in
y out
para el operador de ruta to
. Esto requiere biblioteca 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}
Y una variante en la que las conexiones rectas (a) -- (b)
y (a) -- (c)
se conectan en las esquinas. En este caso podría verse mejor.
\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}