1

I want to add a legend to my graph, explaining what different arrows mean. I thought I might be able to do it using coordinates, but the spaces between them are the same as spaces between the nodes in the graph itself, and I want only a short distance between them. I know there is a simple way but I can't figure it out.

Also how do I add writing next to the arrow, explaining its purpose, and labelling the legend as such?

Current attempt

    \begin{tikzpicture}[
            > = stealth, % arrow head style
            shorten > = 1pt, % don't touch arrow head to node
            auto,
            node distance = 3cm, % distance between nodes
            semithick % line style
        ]
        \tikzstyle{every state}=[
            draw = black,
            thick,
            fill = white,
            minimum size = 10mm
        ]

        \node[state] (A) {$A$};
        \node[state] (B) [right of=A] {$B$};
        \node[state] (C) [below of=A] {$C$};

\tikzset{mystyle/.style={->,line width=2pt}} 

        \coordinate[below of=C] (d2);
        \coordinate[right of=d2] (d3);
        \coordinate[below of=d2] (d4);
        \coordinate[right of=d4] (d5);

        \path[->] (A) edge node {} (B);
        \path[->] (A) [mystyle] edge node {} (C);

        \path[->] (d2) edge node {} (d3);
        \path[->] (d4) [mystyle] edge node {} (d5);


    \end{tikzpicture}
2

The following example puts the legend below the lower left corner of the drawing. It does not use the node positioning system, but simple coordinates. Thus the lengths can be controlled easily. Text can be put with node[right] at the end point of the legend arrows:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}

\begin{document}
  \begin{tikzpicture}[
    > = stealth, % arrow head style
    shorten > = 1pt, % don't touch arrow head to node
    auto,
    node distance = 3cm, % distance between nodes
    semithick % line style
  ]
    \tikzstyle{every state}=[
        draw = black,
        thick,
        fill = white,
        minimum size = 10mm
    ]

    \node[state] (A) {$A$};
    \node[state] (B) [right of=A] {$B$};
    \node[state] (C) [below of=A] {$C$};

    \tikzset{mystyle/.style={->,line width=2pt}}

    \path[->] (A) edge node {} (B);
    \path[->] (A) [mystyle] edge node {} (C);

    \draw[->]
      (current bounding  box.south west)
      ++(0, -2em) -- ++(2em, 0)
      node[right] {Thin arrow};
    \draw[mystyle, yshift=-1em]
      (current bounding box.south west)
      ++(0, -1em) -- ++(2em, 0)
      node[right] {Thick arrow};
  \end{tikzpicture}
\end{document}

Result

1

While the answer linked by Claudio should be useful, here is a manual method just for illustration. I have added positioning library and changed the syntax to right = of from right of =. Now you can control the distance by below = 5mm of C route. Further, I have used empty nodes so that the length becomes identical too.

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning,automata}

\begin{document}
    \begin{tikzpicture}[
            > = stealth, % arrow head style
            shorten > = 1pt, % don't touch arrow head to node
            auto,
            node distance = 3cm, % distance between nodes
            semithick % line style
        ]
        \tikzstyle{every state}=[
            draw = black,
            thick,
            fill = white,
            minimum size = 10mm
        ]

        \node[state] (A) {$A$};
        \node[state] (B) [right = of A] {$B$};
        \node[state] (C) [below = of A] {$C$};

\tikzset{mystyle/.style={->,line width=2pt}}

        \node[state,draw = none,below = 5mm of C] (d2) {\phantom{$A$}};
        \node[state,draw = none,right = of  d2] (d3) {\phantom{$B$}};
        \node[state,draw = none,below = 1mm of d2] (d4) {\phantom{$C$}};
        \node[state,draw = none,right = of d4] (d5) {\phantom{$B$}};

        \path[->] (A) edge node {} (B);
        \path[->] (A) [mystyle] edge node {} (C);

        \draw[->] (d2) -- (d3) node[right] {some text here};
        \draw[->,mystyle] (d4) -- (d5)node[right] {some other text here};


    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.