[Tex/LaTex] How to draw a graph in tikz where the vertices are only represented by the label names

graphstikz-pgf

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.

Best Answer

\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