1

I am trying to draw a graph that can only use edges that are either vertical, horizontal, or diagonal at 45 degrees. I am trying to make a graph with 6 vertices and 8 edges. I so far have this:

\begin{tikzpicture}[->,>=stealth',auto,node distance=3cm,
thick,main node/.style={circle,fill=black!30,draw,minimum size=1cm,inner sep=0pt]}]

\node[main node] (v) []{$v$};

\node[main node] (w) [below left of =v] {$w$};

\node[main node] (1)  [left of =v] {$1$};

\node[main node] (2) [above of =w]  {$2$};

\node[main node] (3) [below of =v ]  {$3$};

\node[main node] (4) [right of = w] {$4$};
\path[-]


(v) 

edge node {} (1)
edge node {} (2) 
edge node {} (3) 
edge node {} (4)

(w)  
edge node {} (1)
edge node {} (2) 
edge node {} (3) 
edge node {} (4);

\end{tikzpicture}

But I want it to look like the picture attached, where the pink and blue lines are octilinear.

enter image description here It currently looks like this: enter image description here

Any tips?

1
  • 1
    BTW, the empty nodes (node {}) in the edge-drawing section can be removed. Nov 5 '16 at 17:01
1

I'd place the nodes with explicit coordinates, using variables to express the symmetries. Note that you can scale the picture without recalculating the coordinates (see the option scale=2 of the tikzpicture environment).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
  [->, >=stealth', auto, thick,
   main node/.style=
     {circle, fill=black!30, draw, minimum size=1cm, inner sep=0pt]},
   scale=2
  ]
\newcommand\vx{0.5}
\newcommand\vy{1}
\newcommand\fx{2} % 4.x
\node[main node] (2) at (-\vx,  0 ) {$2$};
\node[main node] (3) at ( \vx,  0 ) {$3$};
\node[main node] (v) at ( \vx, \vy) {$v$};
\node[main node] (w) at (-\vx,-\vy) {$w$};
\node[main node] (1) at (-\fx, \vy) {$1$};
\node[main node] (4) at ( \fx,-\vy) {$4$};
\path[-]
  (v) edge node {} (1)
      edge node {} (2) 
      edge node {} (3) 
      edge node {} (4)
  (w) edge node {} (1)
      edge node {} (2) 
      edge node {} (3) 
      edge node {} (4);
\end{tikzpicture}
\end{document}

enter image description here

2

Well you could try reorganising which nodes you position relative to which

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

\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=3cm,
thick,main node/.style={circle,fill=black!30,draw,minimum size=1cm,inner sep=0pt]}]

\node[main node] (v) []{$v$};
\node[main node] (2) [below left of =v]  {$2$};
\node[main node] (w) [below of =2] {$w$};
\node[main node] (1)  [above left of =2] {$1$};
\node[main node] (3) [below of =v]  {$3$};
\node[main node] (4) [below right of = 3] {$4$};
\path[-]

(v) 
edge node {} (1)
edge node {} (2) 
edge node {} (3) 
edge node {} (4)

(w)  
edge node {} (1)
edge node {} (2) 
edge node {} (3) 
edge node {} (4);

\end{tikzpicture}
\end{document}

enter image description here

Alternatively, while the relative positioning of TikZ can be quite helpful, if you have a specific position in mind you may like to position nodes explicitly, or use a matrix to place them on a grid a bit more naturally as in the example below.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=3cm,
thick,main node/.style={circle,fill=black!30,draw,minimum size=1cm,inner sep=0pt]}]

\matrix (octilinear) [matrix of nodes,nodes={main node},column sep = 2cm,row sep = 2cm]
{
    1 & & & V & & \\
    & & 2 & 3 & & \\
    & & W & & & 4 \\
};

\draw[-] (octilinear-1-1) -- (octilinear-1-4);
\draw[-] (octilinear-1-4) -- (octilinear-2-4);
\draw[-] (octilinear-2-3) -- (octilinear-1-4);
\draw[-] (octilinear-2-3) -- (octilinear-3-3);
\draw[-] (octilinear-3-3) -- (octilinear-3-6);
\draw[-] (octilinear-2-4) -- (octilinear-3-3);
\draw[-] (octilinear-1-1) -- (octilinear-3-3);
\draw[-] (octilinear-1-4) -- (octilinear-3-6);

\end{tikzpicture}
\end{document}

enter image description here

1
  • @HeikoOberdiek agreed, that part was copied without improvement from the OP's MWE
    – Dai Bowen
    Nov 5 '16 at 17:01

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.