5
\begin{tikzpicture}[->,level 1/.style={sibling distance=3cm},auto]
\tikzstyle{vertex}=[draw,circle,minimum size=0.8cm]
\tikzstyle{selected vertex}=[]
\tikzstyle{edge}=[->,node distance=3cm,thick,auto]
\node[vertex](v1)at(0,0){1};
\node[vertex](v2)at(3,-0.5){3};
\node[vertex](v3)at(3,2){2};
\node[vertex](v4)at(2,-1.5){4};
\node[vertex](v5)at(5,2){5};
\node[vertex](v6)at(6,0.5){6};
\node[vertex](v7)at(8,-1.5){7};
\node[vertex](v8)at(8,2){8};
\node[vertex](v9)at(11,2){9};

\draw[edge](v1)--(v2);
\draw[edge](v1)--(v3);
\draw[edge](v1)--(v4);
\draw[edge](v3)--(v5);
\draw[edge](v2)--(v6);
\draw[edge](v2)--(v7);
\draw[edge](v4)--(v7);
\draw[edge](v6)--(v8);

\path[midway,above]node{}(v1)edge node{B}(v2);
\path[midway,above]node{}(v1)edge node{A}(v3);
\path[midway,below]node{}(v1)edge node{C}(v4);
\path[midway,above]node{}(v3)edge node{D}(v5);
\path[midway,above]node{}(v2)edge node{E}(v6);
\path[midway,above]node{}(v2)edge node{F}(v7);
\path[midway,below]node{}(v4)edge node{G}(v7);
\path[midway,above]node{}(v6)edge node{I}(v8);
\path[midway,above]node{}(v5)edge node{H}(v8);
\path[midway,above]node{}(v8)edge node{J}(v9);
\path[midway,above]node{}(v7)edge node{K}(v9);
\end{tikzpicture}

enter image description here

I have drawn above figure,,,, but i want to draw like below ,,, i want help in drawing those home like symbol over the node, and double arrow between particular nodes as in fig below, please guide.

enter image description here

1
  • This question is in fact two: (a) how draw house (b) how to position house. For (b), you can use something like \path (v8)+(1,-1) <house drawing code>;.
    – Symbol 1
    Jun 8, 2019 at 6:38

1 Answer 1

7

This is a possible solution. The house is a node with a upper label (passed as parameter to house style). You can use positioning label to place them around vertexs

There is also an example for double arrow between vertex 4 and 7.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, arrows.meta}

\begin{document}
\begin{tikzpicture}[
    house/.style={
        draw, minimum width=8mm, minimum height=6mm, 
        label={[name=labelaux, inner sep=1mm, distance=0pt]#1}, 
        append after command={%
            \pgfextra \draw ([xshift=.5\pgflinewidth]\tikzlastnode.north west)--(labelaux.north)
                --([xshift=-.5\pgflinewidth]\tikzlastnode.north east);\endpgfextra
        }
    },
    vertex/.style={draw,circle,minimum size=0.8cm},
    ]

\node[vertex](v1)at(0,0){1};
\node[vertex](v3)at(3,-0.5){3};
\node[vertex](v2)at(3,2){2};
\node[vertex](v4)at(2,-1.5){4};
\node[vertex](v5)at(5,2){5};
\node[vertex](v6)at(6,0.5){6};
\node[vertex](v7)at(8,-1.5){7};
\node[vertex](v8)at(8,2){8};
\node[vertex](v9)at(11,2){9};

\path[->, auto] (v1) edge node {A} (v2)
           edge node {B} (v3)
           edge node {C} (v4)
      (v2) edge node {D} (v5)
       (v3) edge node {E} (v6)
            edge node {F} (v7)
      (v4) edge[double equal sign distance, -Implies] node {G} (v7)
      (v5) edge node {H} (v8)
      (v6) edge node {I} (v8)
      (v7) edge node {K} (v9)
      (v8) edge node {J} (v9);

\node[house=3, left=1mm of v1] {0};
\node[house=4, above right=2mm and 1mm of v2] {9};
\end{tikzpicture}
\end{document}

enter image description here

3
  • Sorry to say that but using \pgfextra for a path is not a good idea, nor necessary. Use house/.style={alias=house, draw, minimum width=8mm, minimum height=6mm, label={[name=labelaux, inner sep=1mm, distance=0pt]#1}, append after command={% ([xshift=.5\pgflinewidth]house.north west)--(labelaux.north) --([xshift=-.5\pgflinewidth]house.north east) } }, and then \draw node[house=3, left=1mm of v1] {0}; \draw node[house=4, above right=2mm and 1mm of v2] {9};.
    – user121799
    Jun 8, 2019 at 14:51
  • @marmot It's the first time that I understand how to use append after command. Thank you. But can it be applied when not the whole path shares same drawing options? I'm thinking into a different color/thickness for the roof.
    – Ignasi
    Jun 9, 2019 at 8:01
  • I think you need an edge then: house/.style={alias=house, draw, minimum width=8mm, minimum height=6mm, label={[name=labelaux, inner sep=1mm, distance=0pt]#1}, append after command={% ([xshift=.5\pgflinewidth]house.north west)edge[red](labelaux.north) (labelaux.north)edge[red]([xshift=-.5\pgflinewidth]house.north east) } },. Then you do not need \draw: \node[house=3, left=1mm of v1] {0}; works as in your code.
    – user121799
    Jun 9, 2019 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .