# How do I label the vertices in the following graph?

I have the following code, which generates a graph with vertices

\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}[scale=.7,colorstyle/.style={circle, draw=black!100,fill=black!100, thick, inner sep=0pt, minimum size=2 mm}]
\node at (-9,1)[colorstyle]{};
\node at (-7,1)[colorstyle]{};
\node at (-5,1)[colorstyle]{};
\node at (-3,1)[colorstyle]{};
\node at (-9,-1)[colorstyle]{};
\node at (-7,-1)[colorstyle]{};
\node at (-5,-1)[colorstyle]{};
\node at (-3,-1)[colorstyle]{};
\draw[thick](-9,1)--(-7,1)--(-5,1)--(-3,1);
\draw[thick](-9,-1)--(-7,-1)--(-5,-1)--(-3,-1);
\draw[thick](-9,-1)--(-9,1);
\draw[thick](-7,-1)--(-7,1);
\draw[thick](-5,-1)--(-5,1);
\draw[thick](-3,-1)--(-3,1);
\end{tikzpicture}

\end{center}
\caption{ $C_{4}^{3}$ representing a genus three curve in $\P^{5}$}
\end{figure}


I want to label the vertices. How should I go about doing that?

• Do you want the labels inside or outside the circles? For the former, add some text in the {} of the nodes, for the latter, add something like label=above:txt after colorstyle. – Torbjørn T. Dec 6 '16 at 17:53
• Also, can the labels be any random text, or is there some structure to them, e.g. n_1, n_2 etc. – Torbjørn T. Dec 6 '16 at 17:56
• @TorbjørnT.- I want to label them n_1, n_2. etc – fierydemon Dec 6 '16 at 17:59
• @TorbjørnT.- Which {} are you talking about? Should I put additional {} in front of \node? – fierydemon Dec 6 '16 at 18:01
• The only {} that you can see in for example \node at (-3,1)[colorstyle]{};. You will also need add something like text=white to colorstyle, as black text on black fill is hard to see ... – Torbjørn T. Dec 6 '16 at 18:07

# New code

One method of drawing this using a couple of loops. I don't know if the labels are how you intended though, you haven't been very clear about that. \documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[
colorstyle/.style={
circle, draw=black,fill=black,
thick, inner sep=0pt, minimum size=1 mm,
outer sep=0pt
},
scale=2]

\foreach [count=\j] \x in {0,...,3} {
\node (n-1-\j) at (\x,0) [colorstyle,label=below:$n_\j$]{};
\node (n-2-\j) at (\x,1) [colorstyle,label=above:$m_\j$]{};
\draw [thick] (n-1-\j) -- (n-2-\j);
}
\foreach [remember=\i as \j (initially 1)] \i in {2,...,4} {
\draw [thick] (n-1-\j) -- (n-1-\i);
\draw [thick] (n-2-\j) -- (n-2-\i);
}
\end{tikzpicture}

\end{document}


Or with labels inside vertices. Note I changed the fill colour, increased the inner sep, and moved the location of $n_\j$/$m_\j$ \documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[
colorstyle/.style={
circle, draw=black,fill=black!20,
thick, inner sep=2pt, minimum size=1 mm,
outer sep=0pt
},
scale=2]

\foreach [count=\j] \x in {0,...,3} {
\node (n-1-\j) at (\x,0) [colorstyle]{$n_\j$};
\node (n-2-\j) at (\x,1) [colorstyle]{$m_\j$};
\draw [thick] (n-1-\j) -- (n-2-\j);
}
\foreach [remember=\i as \j (initially 1)] \i in {2,...,4} {
\draw [thick] (n-1-\j) -- (n-1-\i);
\draw [thick] (n-2-\j) -- (n-2-\i);
}
\end{tikzpicture}

\end{document}


Your original code, with labels added similar to above. Note that in the second example I added names to each node, and drew the lines using the node names as coordinates, instead of explicit (x,y)-coords. The benefit of this is that, as you can see on the screenshot above, that the lines stop at the border of the node.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.7,colorstyle/.style={circle, draw=black!100,fill=black!100, thick, inner sep=0pt, minimum size=2mm}]
\node at (-9,1)[colorstyle,label=above:$n_1$]{};
\node at (-7,1)[colorstyle,label=above:$n_2$]{};
\node at (-5,1)[colorstyle,label=above:$n_3$]{};
\node at (-3,1)[colorstyle,label=above:$n_4$]{};
\node at (-9,-1)[colorstyle,label=below:$m_1$]{};
\node at (-7,-1)[colorstyle,label=below:$m_2$]{};
\node at (-5,-1)[colorstyle,label=below:$m_3$]{};
\node at (-3,-1)[colorstyle,label=below:$m_4$]{};
\draw[thick](-9,1)--(-7,1)--(-5,1)--(-3,1);
\draw[thick](-9,-1)--(-7,-1)--(-5,-1)--(-3,-1);
\draw[thick](-9,-1)--(-9,1);
\draw[thick](-7,-1)--(-7,1);
\draw[thick](-5,-1)--(-5,1);
\draw[thick](-3,-1)--(-3,1);
\end{tikzpicture}

\begin{tikzpicture}[scale=.7,colorstyle/.style={circle, draw=black!100,fill=black!20, thick, inner sep=2pt, minimum size=2mm}]
\node (n1) at (-9,1)[colorstyle]{$n_1$};
\node (n2) at (-7,1)[colorstyle]{$n_2$};
\node (n3) at (-5,1)[colorstyle]{$n_3$};
\node (n4) at (-3,1)[colorstyle]{$n_4$};
\node (m1) at (-9,-1)[colorstyle]{$m_1$};
\node (m2) at (-7,-1)[colorstyle]{$m_2$};
\node (m3) at (-5,-1)[colorstyle]{$m_3$};
\node (m4) at (-3,-1)[colorstyle]{$m_4$};
\draw[thick] (n1)--(n2)--(n3)--(n4)--(m4)--(m3)--(m2)--(m1)--(n1);
\draw[thick] (n2)--(m2)
(n3)--(m3);
\end{tikzpicture}
\end{document}