7

I want to draw lines between v_2,...,v_6 and from v_1 to all the other points (a pyramid). This is how far I got:

\documentclass{article}
\usepackage{graphics, tikz, tkz-berge}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1,transform shape]
  \tikzstyle{LabelStyle}=[fill=white,sloped]
  \Vertex[x=0,y=0]{$v_2$}
  \Vertex[x=3,y=0]{$v_3$}
  \Vertex[x=4,y=1.5]{$v_4$}
  \Vertex[x=1.5,y=2.5]{$v_5$}
  \Vertex[x=-1,y=1.5]{$v_6$}
  \Vertex[x=1.5,y=4.5]{$v_1$}
\end{tikzpicture}
\caption{Graph}
\end{figure}
\end{document}

It produces the following graph:

Graph Which is almost okay, but I can't seem to add edges. I tried to add \Edge[]($v_1$)($v_2$) to the code but that gives me the error 'paragraph ended before parse was completed'. Apparently the problem has something to do with the $v_i$ because the code runs if I delete the dollar signs.

7

(Based on the posts in comment, How to reuse vertex names using the tkz-berge graph drawing package? and Referencing a Vertex that has Math Typesetting inside it to make an Edge)

You should separate the labels from the name of the nodes. A minimal patch :

\documentclass{article}
\usepackage{graphics, tikz, tkz-berge}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1,transform shape]
  \tikzstyle{LabelStyle}=[fill=white,sloped]
  \Vertex[x=0,y=0,L=$v_2$]{v2}
  \Vertex[x=3,y=0,L=$v_3$]{v3}
  \Vertex[x=4,y=1.5,L=$v_4$]{v4}
  \Vertex[x=1.5,y=2.5,L=$v_5$]{v5}
  \Vertex[x=-1,y=1.5,L=$v_6$]{v6}
  \Vertex[x=1.5,y=4.5,L=$v_1$]{v1}
  \Edge[](v1)(v2)
  \Edge[](v4)(v5)
  %etc.
\end{tikzpicture}
\caption{Graph}
\end{figure}
\end{document}
7

Another option is not using labels when defining the positions of the vertex, and instead assigning all of them later, with \AssignVertexLabel. Note however that this macro expects the nodes numbered from 0, not from 1 (but you can assign them labels from $_1$).

This is the MWE:

\documentclass{article}
\usepackage{graphics, tikz, tkz-berge}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1,transform shape]
  \tikzstyle{LabelStyle}=[fill=white,sloped]
  \SetVertexNoLabel
  \Vertex[x=0,y=0]{v1}
  \Vertex[x=3,y=0]{v2}
  \Vertex[x=4,y=1.5]{v3}
  \Vertex[x=1.5,y=2.5]{v4}
  \Vertex[x=-1,y=1.5]{v5}
  \Vertex[x=1.5,y=4.5]{v0}
  \AssignVertexLabel{v}{$v_1$,$v_2$,$v_3$,$v_4$,$v_5$,$v_6$}
  \Edges(v5,v4,v0);\Edges(v4,v3)
  \SetUpEdge[color=white,style={double=black,double distance=2pt}]
  \Edges(v0,v3,v2,v1,v5,v0)
  \Edges(v1,v0,v2)
\end{tikzpicture}
\caption{Graph}
\end{figure}
\end{document}

Producing:

Result

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.