新代码

新代码

我有以下代码,它生成带有顶点的图形

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

我想要标记顶点。我应该怎么做?

答案1

新代码

绘制此图的一种方法是用几个循环。我不知道标签是否符合您的预期,您对此还不是很明确。

在此处输入图片描述

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

或者在顶点内使用标签。注意,我更改了填充颜色,增加了,并移动了/inner sep的位置$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}

使用原始代码

您的原始代码,添加了与上面类似的标签。请注意,在第二个示例中,我为每个节点添加了名称,并使用节点名称作为坐标绘制线条,而不是使用明确的 (x,y) 坐标。这样做的好处是,如您在上面的屏幕截图中看到的那样,线条会停止在节点的边界处。

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

相关内容