我怎样才能用两个分割的正方形标记我的节点

我怎样才能用两个分割的正方形标记我的节点

我怎样才能像上面那样在节点上方/下方创建两个小框?我已经写了一个标签,但它不起作用。

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\definecolor{mygreen}{HTML}{29AB87}
\definecolor{myred}{HTML}{9F0101}
\definecolor{myblue}{HTML}{1C4966}


\begin{document}
    \begin{tikzpicture}
    [
    roundnode/.style={circle, draw=mygreen, fill=mygreen!50, very thick, minimum size=7mm},
    squarednode/.style={rectangle, draw=myred, fill=myred!50, very thick, minimum size=5mm},
    square/.style={regular polygon,regular polygon sides=4},
    ]

    %Nodes
    \node at ( 0,0) [roundnode] (node0) {0};
    \node at ( 3,0)[roundnode] (node1) {1} [label={[draw,rectangle split,%<-selects shape
        rectangle split parts=2,%<- 2 node parts
        rectangle split horizontal,%<- horizontal split
        yshift=-1ex]above:{10\nodepart{two}10}}];;;
    \node at ( 3,3) [roundnode] (node2) {2};
    \node at ( 6,3)[roundnode] (node3) {3};
    \node at ( 3,-3)[roundnode] (node4) {4};


    %Lines
    \draw[->] (node0) --node [text width=1.5cm,midway,above=0em] {A(19,0.45)}(node1);
    \draw[->, very thick, myred] (node0) -- node [text width=1.5cm,midway,above=-0.20em, rotate=45, black] {B(19,0.45)}(node2);
    \draw[->, very thick, myred] (node2) -- node [text width=1.5cm,midway,above=0em, black] {C(19,0.45)}(node3);
    \draw[->][dashed] (node1) -- (node2);
    \draw[->] (node0) -- node [text width=1.5cm,midway,above=0em, rotate=-45] {D(19,0.45)}(node4);
\end{tikzpicture}
\end{document}

答案1

你不能[<options>]在任何地方添加。在你的代码中你有

\node at (x,y) [<some style options>]  {<node text>} [<label>];

但是在 之后不能有选项{<node text>}label应该与您之前添加到节点的其他选项一起使用。

\node at (x,y) [<some style options>, <label>] {<node text>};

附注:记录的顺序是

\node [<options>] at (<coordinate>) {<node text>};

尽管它确实可以工作,正如您所写的一样。

对于您问题中的具体代码:

\node at ( 3,0)[roundnode, label={[draw,rectangle split,%<-selects shape
    rectangle split parts=2,%<- 2 node parts
    rectangle split horizontal,%<- horizontal split
    yshift=-1ex]below:{10\nodepart{two}10}}] (node1) {1};

您还需要将\usetikzlibrary{shapes.multipart}库添加到序言中才能使用rectangle split

相关内容