3

I am trying to move the node "H" to one of the two positions shown in red below:

I am not sure how to position it at 'intermediate' positions such as I am suggesting. How could this be done? Is there a more sensible way of defining the positions of the nodes overall? The code is as follows:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}[
    -,
    every loop/.style={},
    auto,
    node distance = 4cm,
    thick,
    main node/.style={
        circle,
        fill=gray!50,
        draw,
        font=\rmfamily\Large\bfseries,
        minimum size=15mm
    }
]

\node[main node] (W) [] {W};
\node[main node] (Z) [right of=W] {Z};
\node[main node] (q) [above right of=Z] {q};
\node[main node] (g) [below right of=q] {g};
\node[main node] (l) [above left of=W] {l};
\node[main node] (gamma) [below left of=l] {${\gamma}$};
\node[main node] (H) [below left of=W] {H};

  \path[
    every node/.style={
        font=\rmfamily\small,
        fill=white,
        inner sep=1pt
    }
]

(H) edge [loop below] node {} (H)
(H) edge [] node {} (W)
(H) edge [] node[right=1mm] {} (Z)
(H) edge [] node[right=1mm] {} (l)
(W) edge [loop left] node[right=1mm] {} (W)
(W) edge [] node[right=1mm] {} (Z)
(q) edge [] node[right=1mm] {} (Z)
(q) edge [] node[right=1mm] {} (W)
(q) edge [] node[right=1mm] {} (H)
(Z) edge [] node[right=1mm] {} (l)
(l) edge [] node[right=1mm] {} (gamma)
(q) edge [] node[right=1mm] {} (gamma)
(q) edge [] node[right=1mm] {} (g)
(g) edge [loop below] node {} (g)
;

\end{tikzpicture}
\end{document}
  • Try \node[main node] (H) [below left of=W] {H};. – Sigur Jun 23 '14 at 15:05
7

I'd suggest adopting positioning library uses which introduced more flexible placement options or convert you diagram into a matrix which is very usefull for such regular constructions.

With positioning you code could be changed to

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{arrows, positioning}
\begin{document}

\begin{tikzpicture}[
    -,
    every loop/.style={},
    auto,
% node distance = 4cm,
% on grid,
    thick,
    main node/.style={
        circle,
        fill=gray!50,
        draw,
        font=\rmfamily\Large\bfseries,
        minimum size=15mm
    }
]

\node[main node] (W) [] {W};
\node[main node] (l) [above left = of W] {l};
\node[main node] (gamma) [below left = of l] {${\gamma}$};
\node[main node] (H) [above right = of W] {H};
\node[main node] (Z) [below right = of H] {Z};
\node[main node] (q) [above right = of Z] {q};
\node[main node] (g) [below right = of q] {g};

  \path[
    every node/.style={
        font=\rmfamily\small,
        fill=white,
        inner sep=1pt
    }
]

(H) edge [loop above] node {} (H)
(H) edge [] node {} (W)
(H) edge [] node[right=1mm] {} (Z)
(H) edge [] node[right=1mm] {} (l)
(W) edge [loop left] node[right=1mm] {} (W)
(W) edge [] node[right=1mm] {} (Z)
(q) edge [] node[right=1mm] {} (Z)
(q) edge [] node[right=1mm] {} (W)
(q) edge [] node[right=1mm] {} (H)
(Z) edge [] node[right=1mm] {} (l)
(l) edge [] node[right=1mm] {} (gamma)
(q) edge [] node[right=1mm] {} (gamma)
(q) edge [] node[right=1mm] {} (g)
(g) edge [loop below] node {} (g)
;

\end{tikzpicture}
\end{document}

and the result is

enter image description here

Update

Following Harish Kumar suggestion a solution with matrix:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{arrows, matrix}
\begin{document}

\begin{tikzpicture}[
    -,
    every loop/.style={},
    auto,
    thick,
    main node/.style={
        circle,
        fill=gray!50,
        draw,
        font=\rmfamily\Large\bfseries,
        minimum size=15mm
    }
]

\matrix (A) [matrix of nodes, nodes={main node}, row sep=8mm, column sep=4mm]{
& I & & H & & q \\
$\gamma$ & & W & & Z & & g\\
};

\path[
    every node/.style={
        font=\rmfamily\small,
        fill=white,
        inner sep=1pt
    }
]

(A-1-4) edge [loop above] node {} (A-1-4)
(A-1-4) edge [] node {} (A-2-3)
(A-1-4) edge [] node[right=1mm] {} (A-2-5)
(A-1-4) edge [] node[right=1mm] {} (A-1-2)
 (A-2-3) edge [loop left] node[right=1mm] {}  (A-2-3)
 (A-2-3) edge [] node[right=1mm] {} (A-2-5)
(A-1-6) edge [] node[right=1mm] {} (A-2-5)
(A-1-6) edge [] node[right=1mm] {}  (A-2-3)
(A-1-6) edge [] node[right=1mm] {}(A-1-4)
(A-2-5) edge [] node[right=1mm] {} (A-1-2)
(A-1-2) edge [] node[right=1mm] {} (A-2-1)
(A-1-6) edge [] node[right=1mm] {} (A-2-1)
(A-1-6) edge [] node[right=1mm] {} (A-2-7)
(A-2-7) edge [loop below] node {} (A-2-7)
;

\end{tikzpicture}
\end{document}
| improve this answer | |
  • What no matrix solution? ;) – user11232 Jun 23 '14 at 23:19
  • Ah, this is perfect. Thank you very much for your suggestions regarding the positioning library and the matrix approach. I'll look into them. – d3pd Jun 23 '14 at 23:28
  • @HarishKumar Did it. ;-) – Ignasi Jun 24 '14 at 9:22
  • Very nice. But I can vote only once :) – user11232 Jun 24 '14 at 10:54

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.