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.

Right now, what I have is

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\tikzstyle{vertex}=[circle, draw, inner sep=0pt, minimum size=6pt]
\newcommand{\vertex}{\node[vertex]}
\begin{document}

\begin{center}
    \begin{tikzpicture}[scale=0.7]
        \vertex[label=$p_1$](p1) at (-1,1.5) {};
        \vertex[label=$p_2$](p2) at (1,1.5) {};
        \vertex[label=$p_3$](p3) at (-1,0) {};
        \vertex[label=$p_4$](p4) at (-1,-1.5) {};
        \vertex[label=$p_5$](p5) at (1,-1.5) {};
    \tikzset{EdgeStyle/.style={->}}
        \Edge(p1)(p3)
        \Edge(p3)(p4)
        \Edge(p1)(p5)
        \Edge(p2)(p4)
        \Edge(p2)(p5);
    \end{tikzpicture}
\end{center}

\end{document}

which produces the following:

bad things

I am fairly new to tikz so I apologize if this is a dumb question, but how do I get it so that, instead of circles, the vertices will only be displayed as the text labels $p_1$, $p_2$, etc. (which should be positioned where the circles currently are)? There will also probably need some padding around the labels so the arrows don't run overlap with them. I'm not sure how to do either of these things.

share|improve this question
    
Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Which package provides \vertex and \Edge? Judging from the syntax, \vertex is a simple \node and you should not use a label but put $p_i$ in the node text: \vertex … {$p_i$}; (as kan’s answer). –  Qrrbrbirlbel May 9 '13 at 1:19
    
@Qrrbrbirlbel alright. –  Alexander Gruber May 9 '13 at 1:29

2 Answers 2

up vote 6 down vote accepted
\documentclass{amsart}
\usepackage{tikz} 
\begin{document}
\begin{center}
\begin{tikzpicture}
    \node (p1) at ( 0, 0) {$p_1$}; 
    \node (p2) at ( 1, 0) {$p_2$};
    \node (p3) at ( 0,-1) {$p_3$};
    \node (p4) at ( 0,-2) {$p_4$};
    \node (p5) at ( 1,-2) {$p_5$};

    \begin{scope}[every path/.style={->}]
       \draw (p1) -- (p3);
       \draw (p3) -- (p4); 
       \draw (p1) -- (p5);
       \draw (p2) -- (p4);
       \draw (p2) -- (p5);
    \end{scope}  
\end{tikzpicture}
\end{center}
\end{document}

Output

graph.png


Things of this kind remind me immediately of Commutative diagrams, so here is the incredibly simple tikz-cd code to achieve your desired goal:

\documentclass{amsart} 
\usepackage{tikz-cd} 
\begin{document}
\begin{tikzcd}
p_1 \arrow{d} \arrow{rdd} & p_2 \arrow{ldd} \arrow{dd}\\
p_3 \arrow{d} &     \\
p_4 & p_5 
\end{tikzcd}
\end{document} 

Output

graphcd.png

share|improve this answer
    
How to scale the picture with tikz-cd without scaling the labels ? I try to find this in the doc, but without success ? –  Alain Matthes May 9 '13 at 6:21
    
@AlainMatthes I think you can use xscale and yscale (or simply scale, which sets both the scales to the same specified value, I think). +1 for showing OP what (s)he wanted to do... –  kan May 9 '13 at 9:09
    
I tried scale but without success. I made a search on the net but with no result –  Alain Matthes May 9 '13 at 9:43
    
@AlainMatthes I'll investigate and let you know. :-) –  kan May 9 '13 at 11:07
1  
@AlainMatthes: I believe you want the row sep and column sep keys. –  Charles Staats Feb 5 at 16:00

A solution with tkz-graph is also simple but you need to avoid to mix tikz and tkz-graph You need if you work with tkz-graph to know some principles.

With the example you give, it's easy to use tikz or tikz-cd, tkz-graph is only useful if you need to set up automatically some styles and if you need to draw some complex graph but with some geometrical requests (vertices on a line , on a square, a circle

\documentclass[11pt]{article}
\usepackage{tkz-graph} % tkz-graph loads tikz

\begin{document}

\begin{center}
    \begin{tikzpicture}%[scale=0.7]
    % initialization
      \SetGraphUnit{2}
      \SetVertexMath
      \GraphInit[vstyle=Empty]
      % vertices
      \Vertex[L=p_1]{p1} \EA[L=p_2](p1){p2}
      \SO[L=p_3](p1){p3}  
      \SO[L=p_4](p3){p4} \EA[L=p_5](p4){p5}
      % edges
      \tikzset{EdgeStyle/.style = {->}}
     \Edges(p1,p3,p4)
     \Edges (p1,p5)  \Edges (p2,p5)  \Edges (p2,p4)
    \end{tikzpicture}
\end{center}

\end{document}

Comments :

  • \SetGraphUnit If you use some automatic placement, you need to fix the node distance with tkz-graph you can use this macro but possible is d=2 cm inside the options of a Vertex for a local modification
  • \SetVertexMath All the label are in Math Mode, so L=p_3 is enough
  • \GraphInit[vstyle=Empty]the choice of the style. Here the node are circle but no draw
  • \Vertex[L=p_1]{p1} the first vertex as you can see, no need to add ; at the end of the command. The reference is p1 but the label is $p_1$.
  • \EA is for east of (I made this package before the existence of the positioning library). \SOis for south etc... you have also SOEA NOWE etc.
  • It's possible to use personal styles with \tikzset{EdgeStyle/.style = {->}} or \tikzset{VertexStyle/.style = {...}} or \tikzset{EdgeStyle/.append style = {->}} etc.

enter image description here

share|improve this answer

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.