我想将节点连接到中心节点周围。示例如下:
我的方法:
\documentclass[border={10pt}]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\begin{document}
\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node distance=1cm,
arrow/.style={->, >=stealth, very thick},
block/.style={rectangle, fill=blue!20, text centered,
rounded corners, minimum height=1em}
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\node[block] (A) {A};
\node[block] (B) [above=of A] {B};
\node[block] (K) [right=of B] {K};
\node[block] (C) [left=of A] {C};
\node[block] (D) [right=of A] {D};
\node[block] (E) [below=of A] {E};
\node[block] (F) [right=of E] {F};
\node[block] (G) [left=of E] {G};
%connect nodes
\draw [arrow] (B.south) -- ++(0,-0) -| (A.north);
\draw [arrow] (C.east) -- ++(0,-0) -| (A.west);
\draw [arrow] (E.north) -- ++(0,-0) -| (A.south);
\draw [arrow] (D.west) -- ++(0,-0) -| (A.east);
\draw [arrow] (F.north) -- ++(0,-0) -| (A.southeast);
\draw [arrow] (G.north) -- ++(0,-0) -| (A.west);
\draw [arrow] (K.south) -- ++(0,-0) -| (A.east);
\end{tikzpicture}
\end{document}
输出:
我无法将节点放入交叉位置,在之间B - D
,,D - E
C - E
之间B - C
。
答案1
我不会用positioning
这个。放置A
像你那样放置节点,然后使用极坐标放置其他节点。你可以为每个节点设置任意角度和距离。
因为看起来你想要直箭头,所以不要使用-|
,这会使你的线条水平然后垂直。简化你的代码并使用\draw [arrow] (B) -- (A);
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
arrow/.style={->, >=stealth, very thick},
block/.style={rectangle, fill=blue!20, text centered,
rounded corners, outer sep=0pt}
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\node[block] (A) {A};
\node[block] at (120:2) (B) {B};
\node[block] at (60:1.5) (K) {K};
\node[block] at (150:1.5) (C) {C};
\node[block] at (-10:2) (D) {D};
\node[block] at (240:2) (E) {E};
\node[block] at (300:1.5) (F) {F};
\node[block] at (210:1.5) (G) {G};
%connect nodes
\draw [arrow] (B) -- (A);
\draw [arrow] (C.south east) -- (A.west);
\draw [arrow] ([yshift=2mm]A.west) -- ([yshift=2mm]C.south east);
\draw [arrow] (E) -- (A);
\draw [arrow] (D) -- (A);
\draw [arrow] (F) -- (A);
\draw [arrow] (G) -- (A);
\draw [arrow] (G) -- (C);
\draw [arrow] (K) -- (A);
\end{tikzpicture}
\end{document}