如何标记此图中的边

如何标记此图中的边

我需要将此图中的边标记为 $a,b,c,..$。请帮我

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
 
\newlength{\R}\setlength{\R}{3.5cm}

\begin{tikzpicture}[bullet/.style={circle, fill, minimum size=2pt,
              inner sep=2pt, outer sep=0pt},nodes=bullet]

\node (circ1) at (45:\R) [bullet,label=right:$1$] {};

\node (circ2) at (90:\R) [bullet,label=above:$2$] {};

\node (circ3) at (135:\R) [bullet,label=left:$3$] {};

\node (circ4) at (180:\R) [bullet,label=left:$4$] {};

\node (circ5) at (225:\R) [bullet,label=left:$5$] {};

\node (circ6) at (270:\R) [bullet,label=below:$6$] {};

\node (circ7) at (315:\R) [bullet,label=right:$7$] {};

\node (circ8) at (360:\R) [bullet,label=right:$0$] {};

 \draw [thick] (circ1) to (circ2) to (circ3) 
  to (circ4) to (circ5) to (circ6) to (circ7)to (circ8) to (circ1)to (circ3) to (circ5) to (circ7) to (circ1) to (circ4) to(circ7) to(circ2) to (circ5) to(circ8) to (circ3) to (circ6);

\draw [thick] (circ1) to (circ5);

\draw [thick] (circ1) to (circ6);

\draw [thick] (circ3) to (circ7);

\end{tikzpicture} 

\end {document}

在此处输入图片描述

答案1

以下是 Jes 建议的简化代码的尝试,使用一个 foreach 循环绘制代码,并建议如何按字母顺序标记代码。我希望您能实现这个目标。如果我误解了什么,请见谅。

\documentclass[border=3.5mm]{standalone}
\usepackage{tikz}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\begin{document} 


\begin{tikzpicture}
    %nodes and labels
    \foreach\x/\y/\z in {0/0/A,2.5/-1/B,5/0/C,6/2.5/D,5/5/E,2.5/6/F,0/5/G,-1/2.5/H}
    \draw [] (\x,\y) circle (1 mm) node[fill=white,draw=black,circle,inner sep=1pt] {\z};
     
    %draw star
    \begin{pgfonlayer}{bg}
    \draw[red ] (0,0)
        \foreach \x/\y/\z in {5/0,5/5,0/5,0/0/A,5/5,2.5/-1,0/5,5/0,2.5/6,0/0,6/2.5,0/5,5/0,-1/2.5,5/5,6/2.5,5/0,2.5/-1,0/0,-1/2.5,0/5,2.5/6,5/5}
        {-- (\x,\y)

        };
        \end{pgfonlayer}
    \end{tikzpicture}
    
\end{document}

在此处输入图片描述

编辑:好的,另一个带有标记边缘的版本。这更符合您的要求吗?

EDIT2:一个更吸引人的版本。注意:使用\behind path节点参数可以使线条连续。

\documentclass[border=3.5mm]{standalone}
\usepackage{tikz}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\begin{document}
    
    
    \begin{tikzpicture}
        \foreach\x/\y/\z in {0/0/1,2.5/-1/2,5/0/3,6/2.5/4,5/5/5,2.5/6/6,0/5/7,-1/2.5/8}
        \draw [] (\x,\y) circle (1 mm) node[fill=white,draw=black,circle,inner sep=1pt] {\z};
        
        \begin{pgfonlayer}{bg}
            \draw[red ] (0,0)
            \foreach \x/\y/\z in {
                5/0/A,
                5/5/B,
                0/5/C,
                0/0/D,
                5/5/E,
                2.5/-1/F,
                0/5/G,
                5/0/EH,
                2.5/6/I,
                0/0/J,
                6/2.5/K,
                0/5/L,
                5/0/EH,
                -1/2.5/M,
                5/5/N,
                6/2.5/O,
                5/0/P,
                2.5/-1/Q,
                0/0/R,
                -1/2.5/S,
                0/5/T,
                2.5/6/U,
                5/5/V
            }
            {-- (\x,\y) node [midway,above, fill=white,circle, text=black,inner sep=0pt,yshift=2pt,behind path] {\tiny\z}
            };
        \end{pgfonlayer}
        
    \end{tikzpicture}
    
\end{document}

没有\behind path

在此处输入图片描述

\behind path

在此处输入图片描述

答案2

绘制图形的一种方法:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}

\newlength{\R}\setlength{\R}{3.5cm}
    \begin{tikzpicture}[
dot/.style = {circle, fill, outer sep=0pt, auto=right},
every edge quotes/.style = {rounded corners=2pt, fill=white, font=\footnotesize, inner sep=0.5pt}
                        ]
\foreach \i [count=\j] in {45,90,...,360}%
    {\node (c\j) [dot, label=\i:\j] at (\i:\R) {};}
\foreach \i [count=\j, count=\k from 2] in {a,b,...,h}%
{
\ifnum\j<8
    \draw[thick] (c\j) to ["\i", auto=right] (c\k);
\else
    \draw[thick] (c\j) to ["\i", auto=right] (c1);
\fi
}

\foreach \i [count=\j from 3] in {i,j,...,m}    % 5
\draw[semithick,gray]   (c1) to[pos=0.1,"\i"] (c\j);
\foreach \i [count=\j from 4] in {n,o,...,r}    % 5
\draw[semithick,gray]   (c2) to[pos=0.1,"\i"] (c\j);
\foreach \i [count=\j from 5] in {s,t,u,v}      % 4
\draw[semithick,gray]    (c3) to[pos=0.1,"\i"] (c\j);
\foreach \i [count=\j from 6] in {x,y,z}        % 3
\draw[semithick,gray]   (c4) to[pos=0.1,"\i"] (c\j);
\foreach \i [count=\j from 7] in {?,??}        % 2
\draw[semithick,gray]   (c5) to[pos=0.1,"\i"] (c\j);
\draw[semithick,gray]   (c6) to[pos=0.1,"???"] (c8);
    \end{tikzpicture}
\end{document}

然而,正如你所看到的,它的边比字母表中的字母还多。此外,标签是如何分布的还不得而知:

在此处输入图片描述

相关内容