# Creating a cyclic graph whose nodes are row vectors [duplicate]

Possible Duplicate:
How would you produce the following exact hexagon?

I'd like to create a hexagonal graph, where the nodes are row vectors and the edges arrows with labels (I'm trying to illustrate a cycle). See my attempt below:

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}

\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick]

\tikzstyle{every state}=[fill=none,draw=none,text=black]

\node[state]         (A)                    {$(1,1,1)$};
\node[state]         (B) [below right of=A] {$(1,1,1)$};
\node[state]         (C) [below of=B]       {$(1,1,1)$};
\node[state]         (D) [below left of=C]  {$(1,1,1)$};
\node[state]         (E) [above left of=D]  {$(1,1,1)$};
\node[state]         (F) [above of = E]     {$(1,1,1)$};

\path (A) edge          node {$A$} (B)
(B) edge          node {$A$} (C)
(C) edge          node {$A$} (D)
(D) edge          node {$A$} (E)
(E) edge          node {$A$} (F)
(F) edge          node {$A$} (A);

\end{tikzpicture}

\end{document}


I want it to be a regular hexagon, which this is not. I also want the ends of the arrows to be closer to the nodes. How can I sort this?

Thanks

-

## marked as duplicate by percusse, Joseph Wright♦Jan 12 '12 at 12:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

## 3 Answers

You could also use absolute coordinates and play with the directions that the x and y unit vectors point:

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}

\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick,x={(1,0)},y={({cos(60)},{sin(60)})}]
\tikzstyle{every state}=[fill=none,draw=none,text=black]
\node[state] (A) at (0,0)  {$(1,1,1)$};
\node[state] (B) at (3,0)  {$(1,1,1)$};
\node[state] (C) at (3,3)  {$(1,1,1)$};
\node[state] (D) at (0,6)  {$(1,1,1)$};
\node[state] (E) at (-3,6) {$(1,1,1)$};
\node[state] (F) at (-3,3) {$(1,1,1)$};
\path (A) edge node {$A$} (B)
(B) edge node {$A$} (C)
(C) edge node {$A$} (D)
(D) edge node {$A$} (E)
(E) edge node {$A$} (F)
(F) edge node {$A$} (A);

\end{tikzpicture}

\end{document}


Edit 1: If you want the hexagon "standing on a corner", you can use this instead:

\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick,x={({cos(30)*1cm},{sin(30)*1cm})},y={({cos(150)*1cm},{sin(150)*1cm})}]
\tikzstyle{every state}=[fill=none,draw=none,text=black]
\node[state] (A) at (0,0)  {$(1,1,1)$};
\node[state] (B) at (3,0)  {$(1,1,1)$};
\node[state] (C) at (6,3)  {$(1,1,1)$};
\node[state] (D) at (6,6)  {$(1,1,1)$};
\node[state] (E) at (3,6) {$(1,1,1)$};
\node[state] (F) at (0,3) {$(1,1,1)$};
\path (A) edge node {$A$} (B)
(B) edge node {$A$} (C)
(C) edge node {$A$} (D)
(D) edge node {$A$} (E)
(E) edge node {$A$} (F)
(F) edge node {$A$} (A);
\end{tikzpicture}


Note that I had to add *1cm as tikz shows some weird behaviour: while some of the dimensions given are interpreted as points, others are interpreted as centimeters. Delete the four *1cm and see for yourself!

-

You can use the node distance in both directions independently. I have approximated the double of sine and cosine values. Also the extra space is reduced by inner sep and outer sep options. If required you can give some negative number to the shorten option for some more extension.

I have cleaned the code a little bit and added another TikZ library, positioning. Notice the difference between your above of=C and my above = of C.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,positioning}

\begin{document}
\begin{tikzpicture}[->,shorten >=0.2pt,auto,%
node distance=1cm and 1.7cm,%
semithick,%
every state/.style={fill=none,draw=none,text=black, outer sep=1pt, inner sep=0}%
]
\node[state]         (A)                    {$(1,1,1)$};
\node[state]         (B) [below right = of A] {$(1,1,1)$};
\node[state]         (C) [below = of B]       {$(1,1,1)$};
\node[state]         (D) [below left = of C]  {$(1,1,1)$};
\node[state]         (E) [above left = of D]  {$(1,1,1)$};
\node[state]         (F) [above = of E]     {$(1,1,1)$};

\path (A) edge          node {$A$} (B)
(B) edge          node {$A$} (C)
(C) edge          node {$A$} (D)
(D) edge          node {$A$} (E)
(E) edge          node {$A$} (F)
(F) edge          node {$A$} (A);
\end{tikzpicture}
\end{document}


-
If I change the nodes so that they aren't all the same, it becomes a bit wonky. How can I fix that? –  Matt Jan 10 '12 at 2:14
It is due to the relative positioning, you can use a simple foreach loop to place the nodes with a better precision such as \foreach \t in {1,...,6}{\node[state] (State\t) at (90-60*\t:2) {$10253453\t$};}; (I just included a long number). Then, you don't need to adjust any node distance option. For labels, you can add to the foreach list as a second variable. –  percusse Jan 10 '12 at 2:24

I'm also adding this solution because it's a bit more concise.

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}

\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick]

\tikzstyle{every state}=[fill=none,draw=none,text=black]

\draw
\foreach \angle/\label in {0/A,60/B,120/C,180/D,240/E,300/F}{
(\angle:3cm) node(\label)[state]  {$(1,1,1)$}
}
\foreach \start/\destination in {A/B,B/C,C/D,D/E,E/F,F/A} {
(\start) edge          node {$A$} (\destination)
};

\end{tikzpicture}

\end{document}

-