如何在图表中添加圆圈和标签

如何在图表中添加圆圈和标签

我怎样才能生成如下所示的图表:

在此处输入图片描述

我的工作如下

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,matrix,positioning,shapes,arrows}
\usetikzlibrary{shapes.geometric, arrows, calc, intersections}
\newcommand{\tikznode}[2]{\relax
    \ifmmode%
    \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};
    \else
    \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
    \fi}

\begin{document}    
    \begin{figure}[!h]
        \centering
        \begin{tikzpicture}
        \centering
        \coordinate (a) at (0,0);
        \coordinate (b) at (3,0);
        \coordinate (c) at (0,-2);
        \coordinate (d) at (3,-2);

        \coordinate (e) at (0.8,1);
        \coordinate (f) at (3.8,1);
        \coordinate (g) at (0.8,-1);
        \coordinate (h) at (3.8,-1);

        \coordinate (i) at (1.6,2);
        \coordinate (j) at (4.6,2);
        \coordinate (k) at (1.6,0);
        \coordinate (l) at (4.6,0);

        \coordinate (m) at (2.4,3);
        \coordinate (n) at (5.4,3);
        \coordinate (o) at (2.4,1);
        \coordinate (p) at (5.4,1);

        \coordinate (q) at (3.2,4);
        \coordinate (r) at (6.2,4);
        \coordinate (s) at (3.2,2);
        \coordinate (t) at (6.2,2);

        \coordinate (u) at (4,5);
        \coordinate (v) at (7,5);
        \coordinate (w) at (4,3);
        \coordinate (x) at (7,3);

        \coordinate (1) at (5,-4);
        \coordinate (2) at (8,-4);
        \coordinate (3) at (5,-6);
        \coordinate (4) at (8,-6);

        \coordinate (5) at (5.8,-3);
        \coordinate (6) at (8.8,-3);
        \coordinate (7) at (5.8,-5);
        \coordinate (8) at (8.8,-5);

        \coordinate (9) at (6.6,-2);
        \coordinate (10) at (9.6,-2);
        \coordinate (11) at (6.6,-4);
        \coordinate (12) at (9.6,-4);

        \draw [fill=black] (a) circle (2pt);
        \draw [fill=black] (b) circle (2pt);
        \draw [fill=black] (c) circle (2pt);
        \draw [fill=black] (d) circle (2pt);
        \draw [fill=red] (e) circle (2pt);
        \draw [fill=red] (f) circle (2pt);
        \draw [fill=red] (g) circle (2pt);
        \draw [fill=red] (h) circle (2pt);
        \draw [fill=red] (i) circle (2pt);
        \draw [fill=red] (j) circle (2pt);
        \draw [fill=red] (k) circle (2pt);
        \draw [fill=red] (l) circle (2pt);
        \draw [fill=red] (m) circle (2pt);
        \draw [fill=red] (n) circle (2pt);
        \draw [fill=red] (o) circle (2pt);
        \draw [fill=red] (p) circle (2pt);
        \draw [fill=black] (u) circle (2pt);
        \draw [fill=black] (v) circle (2pt);
        \draw [fill=black] (w) circle (2pt);
        \draw [fill=black] (x) circle (2pt);
        \draw [fill=black] (1) circle (2pt);
        \draw [fill=black] (2) circle (2pt);
        \draw [fill=black] (3) circle (2pt);
        \draw [fill=black] (4) circle (2pt);
        \draw [fill=red] (5) circle (2pt);
        \draw [fill=red] (6) circle (2pt);
        \draw [fill=red] (7) circle (2pt);
        \draw [fill=red] (8) circle (2pt);
        \draw [fill=black] (9) circle (2pt);
        \draw [fill=black] (10) circle (2pt);
        \draw [fill=black] (11) circle (2pt);
        \draw [fill=black] (12) circle (2pt);

        \draw (d) node[right]{$FTTM_{n+3}$};
        \draw (h) node[right]{$FTTM_{n-2}$};
        \draw (l) node[right]{$FTTM_{n+1}$};
        \draw (p) node[right]{$FTTM_{n}$};
        \draw (x) node[right]{$FTTM_{1}$};
        \draw (4) node[right]{$FTTM_{n+3}$};
        \draw (8) node[right]{$FTTM_{n+2}$};
        \draw (12) node[right]{$FTTM_{n+1}$};

        \draw [thick,blue] (a) -- (e) -- (i) -- (m);
        \draw [thick,blue] (b) -- (f) -- (j) -- (n);
        \draw [thick,blue] (c) -- (g) -- (k) -- (o);
        \draw [thick,blue] (d) -- (h) -- (l) -- (p);
        \draw [thick,blue] (1) -- (5) -- (9);
        \draw [thick,blue] (2) -- (6) -- (10);
        \draw [thick,blue] (3) -- (7) -- (11);
        \draw [thick,blue] (4) -- (8) -- (12);
        \draw [thick,dashed] (m) -- (q) --(u);
        \draw [thick,dashed] (n) -- (r) --(v);
        \draw [thick,dashed] (o) -- (s) --(w);
        \draw [thick,dashed] (p) -- (t) --(x);
        \draw [thick, densely dotted] (a) -- (b) -- (d) -- (c) -- (a);
        \draw [thick, blue] (e) -- (f) -- (h) -- (g) -- (e);
        \draw [thick, blue] (i) -- (j) -- (l) -- (k) -- (i);
        \draw [thick, blue] (m) -- (n) -- (p) -- (o) -- (m);
        \draw [thick, blue] (5) -- (6) -- (8) -- (7) -- (5);
        \draw [thick, densely dotted] (q) -- (r) -- (t) -- (s) -- (q);
        \draw [thick, densely dotted] (u) -- (v) -- (x) -- (w) -- (u);
        \draw [thick, densely dotted] (1) -- (2) -- (4) -- (3) -- (1);
        \draw [thick, densely dotted] (9) -- (10) -- (12) -- (11) -- (9);
        \end{tikzpicture}
        \caption{The assembly graph of $FTTM_{n'}$.}
        \label{figure:assembly-graph-FTTM_{n'}}
    \end{figure}
\end{document}

产生

在此处输入图片描述

请帮忙。

答案1

你可以使用fit它。不过,我也建议让代码更短一些。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes.geometric}

\begin{document}    
 \begin{figure}[!h]
  \centering
  \begin{tikzpicture}[dot/.style={circle,fill,inner sep=1.2pt},
    every label/.append style={font=\tiny}]
   \begin{scope}[declare function={a=1.5;b=0.8;c=1;},z={(-0.4cm,-0.6cm)}]
    \foreach \X/\Y/\Z [count=\N] in {1/dashed/black,%
        {}/dashed/black,n/cyan/red,n+1/cyan/red,n+2/cyan/red}
    {\draw[style/.expanded=\Y,nodes={dot,\Z}] 
        (a,-b,c*\N) node[dot,label={[black]right:$FTTM_{\X}$}](d-br-\N){} edge ++(0,0,c)
        -- (-a,-b,c*\N) node[dot](d-bl-\N){} edge ++(0,0,c)
        -- (-a,b,c*\N) node[dot](d-tl-\N){} edge ++(0,0,c)
        -- (a,b,c*\N) node[dot](d-tr-\N){}edge ++(0,0,c)
        -- cycle ;  }
    \draw[dashed] (a,-b,6*c) node[dot,label={[black]right:$FTTM_{n+3}$}] (d-br-6){}
        -- (-a,-b,6*c) node[dot] (d-bl-6){}
        -- (-a,b,6*c) node[dot] (d-tl-6){}
        -- (a,b,6*c) node[dot] (d-tr-6){} -- cycle;
   \end{scope}  
   \node[ellipse,draw=red,fit=(d-bl-6)(d-tr-4),inner sep=0pt](c){}; 
   \begin{scope}[xshift=6.5cm,yshift=-1cm,local bounding box=R,
    declare function={a=1.2;b=0.9;c=1.5;},
    z={(-0.5cm,-0.4cm)},every edge/.append style={cyan,solid}]
    \foreach \X/\Y/\Z [count=\N] in {n+1/dashed/black,%
        n+2/cyan/red}
    {\draw[style/.expanded=\Y,nodes={dot,\Z}] 
        (a,-b,c*\N) node[dot,label={[black]right:$FTTM_{\X}$}](dp-br-\N){} edge ++(0,0,c)
        -- (-a,-b,c*\N) node[dot](dp-bl-\N){} edge ++(0,0,c)
        -- (-a,b,c*\N) node[dot](dp-tl-\N){} edge ++(0,0,c)
        -- (a,b,c*\N) node[dot](dp-tr-\N){}edge ++(0,0,c)
        -- cycle ;  }
    \draw[dashed] (a,-b,3*c) node[dot,label={[black]right:$FTTM_{n+3}$}] (d-br-6){}
        -- (-a,-b,3*c) node[dot] (d-bl-6){}
        -- (-a,b,3*c) node[dot] (d-tl-6){}
        -- (a,b,3*c) node[dot] (d-tr-6){} -- cycle;
   \end{scope}  
   \draw[red,-stealth] (c) -- (R);
  \end{tikzpicture}
  \caption{The assembly graph of $FTTM_{n'}$.}
  \label{figure:assembly-graph-FTTM_{n'}}
 \end{figure}
\end{document}

在此处输入图片描述

相关内容