Tikz 中多边形角之间的箭头

Tikz 中多边形角之间的箭头

在下面的代码中,是否可以使箭头的起点和终点位于六边形每个角周围的圆圈处,而不是中心?我也尝试在箭头上贴上标签,但似乎角(而不是节点)之间的箭头表现得很奇怪。欢迎提出任何想法!

此代码的结果:箭头指向中心,找不到如何做标签

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\begin{document}
\begin{tikzpicture}
  \begin{scope}[%
every node/.style={anchor=west,
regular polygon, 
regular polygon sides=6,
draw,
minimum width=2cm,
outer sep=0,
},
      transform shape]
    \node (A) {};
    \node (B) at (A.corner 1) {};
    \node (C) at (B.corner 5) {};
    \node (D) at (A.corner 5) {};
    \foreach \hex in {A,...,D}
    {
      \foreach \corn in {1,3,5}
        \draw[fill=white] (\hex.corner \corn) circle (2pt); 
        \foreach \corn in {2,4,6}
        \draw[fill=gray] (\hex.corner \corn) circle (2pt); 

    }
        \draw [->,color=red] 
    (B.corner 4) edge (B.corner 5)
    (B.corner 4) edge (B.corner 3)
    (B.corner 4) edge (D.corner 3)
    ;
    \draw[->, color=blue] 
    (D.corner 2) edge (D.corner 6)
    (D.corner 2) edge (D.corner 4)
    (D.corner 2) edge (B.corner 6)
    ;
  \end{scope}
\end{tikzpicture}
\end{document}

答案1

欢迎来到 TeX.SE!我提出以下建议。使用节点作为圆圈是告诉箭头在节点边界处停止的标准方法。此外,当您有多个从同一节点开始的边时,您不需要重复起始节点(这是edgeto操作之间的重要区别)。

\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{quotes, shapes}

\begin{document}

\begin{tikzpicture}
  \begin{scope}[nodes={draw, anchor=west, regular polygon,
                       regular polygon sides=6, minimum width=2cm, outer sep=0,
                }]
    \node (A) {};
    \node (B) at (A.corner 1) {};
    \node (C) at (B.corner 5) {};
    \node (D) at (A.corner 5) {};
  \end{scope}

  \begin{scope}[nodes={draw, circle, inner sep = 0pt, minimum width=4pt}]
  \foreach \hex in {A,...,D}
    {
       \foreach[evaluate=\corn as \nodeName using "\hex-\corn"] \corn in {1,3,5}
         \node[fill=white] (\nodeName) at (\hex.corner \corn) {};

       \foreach[evaluate=\corn as \nodeName using "\hex-\corn"] \corn in {2,4,6}
         \node[fill=gray] (\nodeName) at (\hex.corner \corn) {};
    }
  \end{scope}

  \begin{scope}[nodes={circle, line width=0pt, inner sep=1pt},
                every edge/.style={draw, ->, auto},
                every edge quotes/.style={font=\footnotesize}]
    \path [color=red]
      (B-4) edge["$b_5$"'{pos=0.7, inner sep=0pt}] (B-5)
            edge["$b_3$"]                          (B-3)
            edge["$d_3$"']                         (D-3);
    \path [color=blue]
      (D-2) edge["$d_6$"'{inner sep=0pt}]          (D-6)
            edge["$d_4$"]                          (D-4)
            edge["$b_6$"]                          (B-6);
  \end{scope}
\end{tikzpicture}

\end{document}

截屏

相关内容