Tikz 图例的节点之间的不同空间

Tikz 图例的节点之间的不同空间

我想在图表中添加图例,解释不同箭头的含义。我以为我可以使用坐标来实现,但它们之间的空间与图表本身中节点之间的空间相同,而且我只希望它们之间的距离很短。我知道有一种简单的方法,但我不知道该怎么做。

另外,我该如何在箭头旁边添加文字,解释其用途,并标记图例?

当前尝试

    \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}

答案1

以下示例将图例放在图形的左下角。它不使用节点定位系统,而是使用简单的坐标。因此可以轻松控制长度。文本可以放在node[right]图例箭头的端点处:

\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}

结果

答案2

虽然 Claudio 链接的答案应该很有用,但这里仅提供一种手动方法以供说明。我添加了positioning库并将语法更改为right = offrom right of =。现在您可以通过路线控制距离below = 5mm of C。此外,我使用了空节点,以便长度也变得相同。

\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}

在此处输入图片描述

相关内容