Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
You should have a look at tex.stackexchange.com/a/78113/34551 and tex.stackexchange.com/a/95801/34551 probably contains your solution. –  Clément Jun 11 at 10:14
    
@Clément The second link helped me, thank you! –  Jolien Jun 11 at 10:21
add comment

2 Answers 2

up vote 7 down vote accepted

(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}
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.