[Tex/LaTex] How to label the vertices in the following graph

graphs

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?

Best Answer

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.

enter image description here

\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$

enter image description here

\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}

Using your original code

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}
Related Question