TikZ Graph:如何将节点定位在中间以避免重叠?

TikZ Graph:如何将节点定位在中间以避免重叠?

我正在尝试重现以下图表: enter image description here 这是实际结果: enter image description here

虽然不完全相同,但可以接受,但是在某个点,有两个节点(MD,ND)重叠。我该如何将其中一个节点定位在中间以避免这种情况?此外,这是创建图表的最佳方法吗,还是有更好的方法?

这是我的 MWE:

%Begin with any document class:
\documentclass{standalone}
%Load the tkz-graph package:
\usepackage{tkz-graph}
%Specify a basic style:
\GraphInit[vstyle = Shade]
%Customize element styles as desired using standard TikZ syntax:
\tikzset{
    LabelStyle/.style = { rectangle, rounded corners,
    draw, minimum width = 2em,
    fill = yellow!50,
    text = red, font = \bfseries },
    VertexStyle/.append style = { inner sep=5pt,
    font = \Large\bfseries},
    EdgeStyle/.append style = {->}%, bend left} 
}
%Begin the document:
\begin{document}
%Start a tikzpicture environment:
\begin{tikzpicture}
%Set the distance between vertices. The default is 1 for 1 cm.
\SetGraphUnit{7}:

%Declare a first vertex FD:
\Vertex{FD}
%Set a vertex A to the west (WE) and C to the east (EA) relative to the vertex B (B):
\NO(FD){PD}
\SO(FD){TD}
\NOEA(PD){pFD}
\EA(PD){softFD}
\EA(softFD){PuD}
\EA(PuD){AFD}
\EA(FD){MFD}
\EA(MFD){DD}
\EA(DD){ADD}
\SO(MFD){MD}
\SO(MD){FFD}
%The following row is the overlapping node
%\EA(TD){ND}
\SO(FFD){TMFD}
\SO(DD){CoD}
\EA(CoD){ACoD}
\SO(CoD){CMD}
\SO(CMD){SFD}
%Draw edges between the vertices:
\Edge[](FD)(PD)
\Edge[](FD)(TD)
\Edge[](FD)(softFD)
\Edge[](FD)(PuD)
\Edge[](FD)(AFD)
\Edge[](FD)(MFD)
\Edge[](FD)(MD)
\Edge[](FD)(FFD)
\Edge[](FFD)(SFD)
\Edge[](FFD)(TMFD)
\Edge[](MD)(CoD)
\Edge[](MD)(CMD)
\Edge[](MFD)(CoD)
\Edge[](CoD)(ACoD)
\Edge[](MFD)(DD)
\Edge[](DD)(ADD)
\Edge[](PD)(pFD)
\Edge[](softFD)(pFD)
%Add loops, which are edges from a vertex to itself:
%\Loop[dist = 4cm, dir = NO, label = 5](A.west)
%\Loop[dist = 4cm, dir = SO, label = 6](C.east)
%Adjust the bend angle of the edges for the final two wider edges:
%\tikzset{EdgeStyle/.append style = {bend left = 50}}
%\Edge[label = 7](A)(C)
%\Edge[label = 8](C)(A)
%End the picture and the document:
\end{tikzpicture}
\end{document}

答案1

我不知道您想要该节点的具体位置,但您可以为各个节点设置单位距离,例如:

\EA[unit=3.5](TD){ND}

3.5在此处使用是因为您有\SetGraphUnit{7}更多内容。使用上面的代码,节点将放置在和 的ND中间。TDMD

答案2

我建议用其他方法绘制这种复杂的图表,这样你就能得到更好的结果。我使用相对于附近另一个圆的坐标绘制每个圆。此代码\draw (20) ++(-90:1.5cm) node (22) {CMD};表示从圆号 20 开始在 -90 度和 1.5 厘米处绘制圆,并在圆内写入 CMD,并将圆命名为圆号 22。

\documentclass{article}
\usepackage{tikz}
\usepackage{verbatim}

%package for preview
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}

\begin{document}
\begin{tikzpicture}
% define the angle of first hand of FD
\def \angl{360/17}

% draw FD in the center
\draw (0,0) node[draw, circle,radius=2.5cm,very thick] (FD) 
{\huge\bfseries FD};

% draw all the circle based on their neighbours
{\tikzstyle{every node}=[draw,circle,inner sep=2pt,fill=white]
\draw (FD) ++(\angl*0:4cm) node (1) {MFD};
\draw (FD) ++(\angl*1:4cm) node (2) {AFD};
\draw (FD) ++(\angl*2:4cm) node (3) {PuD};
\draw (FD) ++(\angl*3:4cm) node (4) {softFD};
\draw (FD) ++(\angl*4:4cm) node (5) {PD};
\draw (FD) ++(\angl*5:4cm) node (6) {CD};
\draw (FD) ++(\angl*6:4cm) node (7) {CFD};
\draw (FD) ++(\angl*7:4cm) node (8) {XCFD};
\draw (FD) ++(\angl*8:4cm) node (9) {$\sigma\theta$XFD};
\draw (FD) ++(\angl*9:5cm) node (10) {NuD};
\draw (FD) ++(\angl*10:4cm) node (11) {PAC};
\draw (FD) ++(\angl*11:4cm) node (12) {OD};
\draw (FD) ++(\angl*12:4cm) node (13) {RUD};
\draw (FD) ++(\angl*13:4cm) node (14) {TD};
\draw (FD) ++(\angl*14:4cm) node (15) {ND};
\draw (FD) ++(\angl*15:4cm) node (16) {FFD};
\draw (FD) ++(\angl*16:4cm) node (17) {MD};
\draw (1)  ++(0:1.5cm) node (18) {DD}
           ++(0:1.5cm) node (19) {ADD};
\draw (17) ++(0:1.5cm) node (20) {Cod}
           ++(0:1.5cm) node (21) {ACoD};
\draw (20) ++(-90:1.5cm) node (22) {CMD};
\draw (16) ++(-90:1.5cm) node (23) {TMFD}
           ++(0:1.5cm) node (24) {SFD};
\draw (12) ++(180:2cm) node (25) {SD}
           ++(180:1.5cm) node (26) {CSD}
           ++(-90:1.5cm) node (27) {preFD}
           ++(0:1.5cm) node (28) {OFD}
           ++(-60:1.5cm) node (29) {POD}
           ++(0:1.5cm) node (30) {$\mathrm{OD}_{\mathrm{K}}$}
           ++(0:1.5cm) node (31) {$\mathrm{OD}_{\mathrm{EA}}$};
\draw (7)  ++(90:2.5cm) node (32) {eCFD};
\draw (7)  ++(135:2.5cm) node (33) {$\mathrm{CFD}^{\mathrm{P}}$};
\draw (7)  ++(180:3cm) node (34) {$\mathrm{CFD}^{\mathrm{C}}$};
\draw (5)  ++(60:1.5) node (35) {pFD};
}

% draw first hand arrow of FD
\foreach \c in {1,...,17}
{\draw[->,thick] (FD) edge (\c);}

% draw other arrow
\draw[->,thick] (1) edge (18);
\draw[->,thick] (18) edge (19);
\draw[->,thick] (17) edge (20);
\draw[->,thick] (20) edge (21);
\draw[->,thick] (1) edge (20);
\draw[->,thick] (17) edge (22);
\draw[->,thick] (16) edge (23);
\draw[->,thick] (16) edge (24);
\draw[->,thick] (12) edge (25);
\draw[->,thick] (12) edge (28);
\draw[->,thick] (25) edge (26);
\draw[->,thick] (28) edge (27);
\draw[->,thick] (12) edge (29);
\draw[->,thick] (12) edge (30);
\draw[->,thick] (12) edge (31);
\draw[->,thick] (7) edge (32);
\draw[->,thick] (7) edge (33);
\draw[->,thick] (7) edge (34);
\draw[->,thick] (10) edge (34);
\draw[->,thick] (5) edge (35);
\draw[->,thick] (4) edge (35);

\end{tikzpicture}
\end{document}

What you get if you compile the code.

这就是结果。

相关内容