tikz:右彎矩形資訊集

tikz:右彎矩形資訊集

我有這個代碼

\documentclass[10pt]{article}
\begin{document}
\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5}
}
\begin{tikzpicture}[grow = right, scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=15mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=15mm]
    \tikzstyle{level 3}=[level distance=15mm, sibling distance=15mm]

    % The Tree
    \node(0)[solid node,label=left:{$N$}]{} 
    child{node(1)[solid node, white]{}
    }
    child{[white] node(2)[solid node, xshift=20]{}  %note that you need to adjust the yshift if you change the sibling distance
    child{[black] node[hollow node,label=right:{$(a,b)$}]{} edge from parent node[below]{$C$}}
    child{[black] node[hollow node,label=right:{$(c,d)$}]{} edge from parent node[above]{$D$}}
    edge from parent node[black, xshift=40,yshift=0]{$\alpha$} %note that you need to adjust the yshift if you change the level distance
    }
    child{node(3)[solid node, white]{}
    };
    % information set
    \draw[solid,bend right](1)to(3);
    \draw[dashed,rounded corners=7]($(1)+(.25,-.25)$)rectangle($(3)+(-.25,.25)$);
    \end{tikzpicture}
    \end{document}

產生這棵樹的

在此輸入影像描述

如何將矩形向右彎曲?我試過這段程式碼:

\draw[dashed,rounded corners=7, bend right]($(1)+(.25,-.25)$)rectangle($(3)+(-.25,.25)$);

但這不起作用!任何想法?謝謝!

答案1

像這樣?

螢幕截圖

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5}
}
\begin{document}
\begin{tikzpicture}[grow = right, scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=15mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=15mm]
    \tikzstyle{level 3}=[level distance=15mm, sibling distance=15mm]

    % The Tree
    \node(0)[solid node,label=left:{$N$}]{} 
    child{node(1)[solid node, white]{}
    }
    child{[white] node(2)[solid node, xshift=20]{}  %note that you need to adjust the yshift if you change the sibling distance
    child{[black] node[hollow node,label=right:{$(a,b)$}]{} edge from parent node[below]{$C$}}
    child{[black] node[hollow node,label=right:{$(c,d)$}]{} edge from parent node[above]{$D$}}
    edge from parent node[black, xshift=40,yshift=0]{$\alpha$} %note that you need to adjust the yshift if you change the level distance
    }
    child{node(3)[solid node, white]{}
    };
    % information set
    \draw[solid,bend right](1)to(3);
    %\draw[dashed,rounded corners=7]($(1)+(.25,-.25)$)rectangle($(3)+(-.25,.25)$);
    \coordinate (a) at ($(1.center)+(-.25,0)$);
    \coordinate (b) at ($(1.center)+(.25,0)$);
    \coordinate (c) at ($(3.center)+(.25,0)$);
    \coordinate (d) at ($(3.center)+(-.25,0)$);
    \draw[dashed,rounded corners=7] (1)--(b)to[bend right](c)--(d)to[bend left](a)--(1);
    \end{tikzpicture}
\end{document}

相關內容