我定义并定位了五个节点,如下所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\renewcommand{\figurename}{Figure}
\begin{figure}[!htb]
\begin{tikzpicture} [title/.style={font=\fontsize{18}{18}\color{black!45}},
block/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=4em},
bloc/.style={rectangle, draw, fill=green!23, rounded corners, minimum height=2em},
store/.style={cylinder, draw, shape border rotate=90, aspect=0.4, minimum height=1.5cm, minimum width=1.2cm, fill=cyan!23},
dot/.style={circle, fill=black, minimum size=2pt, inner sep=0pt, outer sep=2pt},
blob/.style={cloud, draw, cloud puffs=17.8, cloud ignores aspect, minimum width=4cm, minimum height=2.5cm, align=center},
link/.style={latex-latex, shorten <=8pt, shorten >=1pt}]
% Place nodes
\node [title] (backend) at (5.5,10.05) {Sample};
\node [block, outer sep=5pt, align=center] (server3) at (3.7,6.75) {Component A};
\node [block, outer sep=5pt, align=center] (server1) at (7.15,9.0) {Component B\\(Blah)};
\node [block, outer sep=5pt, align=center] (server2) at (7.15,7.45) {Component C\\(Blah)};
\node [block, outer sep=5pt, align=center] (server4) at (7.15,5.9) {Component D\\(Blah)};
\node [block, outer sep=5pt, align=center] (server5) at (7.15,4.35) {Component E\\(Blah)};
\node [draw=black!50, fit={(backend) (server1) (server2) (server3) (server4) (server5)}] (sample) {};
\end{tikzpicture}
\caption{A Test Graph}
\end{figure}
\end{document}
我想在Component A
其他四个节点之间制作浮动图表样式的箭头,并且我希望它们看起来像这个问题的答案:tikz-qtree 中的水平层次树:较长的节点名称的布局不好,但两端都有箭头换句话说,忽略其他部分,在我的例子中,将 替换nice-child0
为Component A
,并将grandchild0-0
-grandchild0-3
替换为Component B
- 。Component E
有没有不使用树包就可以做到这一点?
答案1
像这样吗?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\renewcommand{\figurename}{Figure}
\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture} [title/.style={font=\fontsize{18}{18}\color{black!45}},
block/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=4em},
bloc/.style={rectangle, draw, fill=green!23, rounded corners, minimum height=2em},
store/.style={cylinder, draw, shape border rotate=90, aspect=0.4, minimum height=1.5cm, minimum width=1.2cm, fill=cyan!23},
dot/.style={circle, fill=black, minimum size=2pt, inner sep=0pt, outer sep=2pt},
blob/.style={cloud, draw, cloud puffs=17.8, cloud ignores aspect, minimum width=4cm, minimum height=2.5cm, align=center},
link/.style={latex-latex, shorten <=8pt, shorten >=1pt}]
% Place nodes
\node [title] (backend) at (5.5,10.05) {Sample};
\node [block, outer sep=5pt, align=center] (server3) at (3.7,6.75) {Component A};
\node [block, outer sep=5pt, align=center] (server1) at (7.15,9.0) {Component B\\(Blah)};
\node [block, outer sep=5pt, align=center] (server2) at (7.15,7.45) {Component C\\(Blah)};
\node [block, outer sep=5pt, align=center] (server4) at (7.15,5.9) {Component D\\(Blah)};
\node [block, outer sep=5pt, align=center] (server5) at (7.15,4.35) {Component E\\(Blah)};
\node [draw=black!50, fit={(backend) (server1) (server2) (server3) (server4) (server5)}] (sample) {};
\foreach \i in {1,2,4,5}
\draw[<->] (server3.east) -- +(10pt,0) |- (server\i.west);
\end{tikzpicture}
\caption{A Test Graph}
\end{figure}
\end{document}
而不是“手动”添加10pt
到 x 坐标中
\foreach \i in {1,2,4,5}
\draw[<->] (server3.east) -- +(10pt,0) |- (server\i.west);
可以使用
\foreach \i in {1,2,4,5}
\draw[<->] let \p1= (server2.west|-server3.east) in
(server3.east) -- +( $ 0.5*(\x1,\y1) - 0.5*(server3.east) $ ) |- (server\i.west);