4

I am learning to draw graphs for my thesis and came up with the following ugly result:

\documentclass[tikz]{standalone}
\usetikzlibrary{cd,graphs,graphs.standard}
\begin{document}
  \begin{tikzpicture}
  \graph [simple, nodes={empty nodes, fill, circle, inner sep=1pt, draw}] {
    subgraph I_n [n=4, grid placement, radius=2cm];
   3[label=left:$v_3$]--["$K_1$"]1[label=left:$v_1$]--["$K_2$"]4[label=right:$v_4$]--["$K_4$"']2[label=right:$v_2$];
  };
  \end{tikzpicture}
\end{document}

Ugly graph

The label "K_2" is positioned inappropriately, but I guess it will be better if the graph is scaled such that the edges are longer. Neither scale=2, nor radius=2cm (see How to scale a tikz graph) works. The latter option does work if I replace grid placement by clockwise, but I prefer the positioning of the nodes as presented in the image.

How can I solve this?

Note: Maybe the graphs library is a bit of overkill for this case, but I am trying to find some kind of generic way for drawing graphs, since I will have to draw complex examples later on.

7

By default, x and y are each units of 10mm. However, you can change this for a picture or a scope. For example,

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{cd,graphs,graphs.standard}
\begin{document}
  \begin{tikzpicture}[x=20mm, y=20mm]
  \graph [simple, nodes={empty nodes, fill, circle, inner sep=1pt, draw}] {
    subgraph I_n [n=4, grid placement];
   3[label=left:$v_3$]--["$K_1$"]1[label=left:$v_1$]--["$K_2$"]4[label=right:$v_4$]--["$K_4$"']2[label=right:$v_2$];
  };
  \end{tikzpicture}
\end{document}

scaled units to spread graph

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.