5

In the code below, is it possible to make the arrows start and stop at the circle around each corner of the hexagon, not in the center? I am also trying to put labels on the arrows, but it seems that arrows between corners (not nodes) behave strangely. Any ideas welcome!

Result of this code: arrows point to the center, can't find how to do labels

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

6

Welcome to TeX.SE! I propose the following. Using nodes for the circles is the standard way to tell arrows to stop at the node boundary. Also, when you have several edges that start from the same node, you don't need to repeat the starting node (this is an important difference between the edge and to operations).

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

screenshot

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.