在图形周围绘制虚线

在图形周围绘制虚线

我正在尝试绘制这些图形,但在如何绘制虚线方面遇到了一些麻烦。

在此处输入图片描述

代码:

\begin{tikzpicture}
\tikzset{roundnode/.style = {thick, draw = black, fill = black, outer sep = 1.5, circle, minimum size = 2pt, scale = 0.75}}

%%%%%%%%% Nodes %%%%%%%%% 
\node[roundnode = black] (A) at (9, 11){};
\node[roundnode = black] (B) at (9, 10){};
\node[roundnode = black] (C) at (7, 9){};
\node[roundnode = black] (D) at (8.4, 9){};
\node[roundnode = black] (E) at (9.6, 9){};
\node[roundnode = black] (F) at (11, 9){};

%%%%%%%%% Edges %%%%%%%%% 
\draw[very thick] (A) to node[left, above, sloped]{}(B);
\draw[very thick] (B) to node[left, above, sloped]{}(C);
\draw[very thick] (B) to node[left, above, sloped]{}(D);
\draw[very thick] (B) to node[left, above, sloped]{}(E);
\draw[very thick] (B) to node[left, above, sloped]{}(F);
\end{tikzpicture}

答案1

像这样::

在此处输入图片描述

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[font=\footnotesize]
        
        % Specify spacing for each level of the tree
        
        \tikzstyle{level 1}=[level distance=12mm,sibling distance=40mm]
        \tikzstyle{level 2}=[level distance=15mm,sibling distance=15mm]
        \tikzset{
            solid node/.style={circle,draw,inner sep=1,fill=black},
                }
        % The Tree
        \node(0)[solid node]{}
        child{node(1)[solid node]{}
            child{node[solid node]{}edge from parent node [left, xshift=-2pt]{2}}
            child{node[solid node]{}edge from parent node [left, xshift=-2pt]{2}}
            child{node[solid node]{}edge from parent node [left, xshift=-2pt]{2}}
            child{node[solid node]{}edge from parent node [left, xshift=-2pt]{2}}           
            edge from parent node [left ]{1}}
        ;
        
        
    \end{tikzpicture}
    
    
\end{document}

编辑--第二张图

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{calc, shapes, fit}
\begin{document}
    \begin{tikzpicture}[font=\footnotesize]
        
        % Specify spacing for each level of the tree
        
        \tikzstyle{level 1}=[level distance=12mm,sibling distance=40mm]
        \tikzstyle{level 2}=[level distance=15mm,sibling distance=15mm]
        \tikzset{
            solid node/.style={circle,draw,inner sep=1,fill=black},
                }
        % The Tree
        \node(0)[solid node]{}
        child{node(1)[solid node]{}
            child{node(2)[solid node]{}edge from parent [draw =none]{}}
            child{node(3)[solid node]{}edge from parent [draw =none]{}}
            child{node(4)[solid node]{}edge from parent [draw =none]{}}
            child{node(5)[solid node]{}edge from parent [draw =none]{}}                 
            edge from parent node [left ]{1}}
        ;
        \node[fit=(0)(1),dashed, draw, ellipse,inner sep=5pt] {};
        \node[fit=(2),dashed, draw, circle,inner sep=5pt, label=-90:2] {};
        \node[fit=(3),dashed, draw, circle,inner sep=5pt,label=-90:2] {};
        \node[fit=(4),dashed, draw, circle,inner sep=5pt,label=-90:2] {};
        \node[fit=(5),dashed, draw, circle,inner sep=5pt,label=-90:2] {};
    \end{tikzpicture}
    
    
\end{document}

在此处输入图片描述

相关内容