创建大型星形图

创建大型星形图

我正在尝试在 Latex 中创建星形图。我的图可能有任意数量的顶点,因此我尝试将这一事实纳入绘图中。这是我到目前为止所做的:

%My Macros:
\usepackage{amsmath,amsthm,amssymb,bbm,mathtools}
\usepackage{xcolor}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{blkarray} %for stating column index
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\caption{Star Graph}
\begin{tikzpicture}
\label{star_poa}
\def \n {20}
\def \N {8}
\def \radius {3cm}
\def \rd {1mm}
\def \rer {4mm}

\def \margin {8} % margin in angles, depends on the radius

\node[draw, circle] at (360:0mm) {$u_*$};
  \node[draw, circle] at ({360/\n *\n / 4}:\radius) {$u_{1}$};
    \node[draw, circle] at ({360/4 - 360/\n * (2 - 1)}:\radius) {$u_2$};
        \node[draw, circle] at ({360/4 - 360/\n * (3 - 1)}:\radius) {$u_3$};
        \node[draw, circle] at ({360/4 - 360/\n * (4 - 1)}:\radius) {$u_4$};

    \node[draw, circle] at ({360/4 + 360/\n * (2 - 1)}:\radius) {$u_t$};        

\path
({360/4 - 360/\n * (1 - 1)}:{\rer}) edge node [left] {a} ({360/4 - 360/\n * (1 - 1)}:\radius-\margin-\rd);

\path
({360/4 - 360/\n * (2 - 1)}:{\rer}) edge node [left] {a} ({360/4 - 360/\n * (2 - 1)}:\radius-\margin-\rd);

\path
({360/4 - 360/\n * (3 - 1)}:{\rer}) edge node [left] {a} ({360/4 - 360/\n * (3 - 1)}:\radius-\margin-\rd);
\path
({360/4 - 360/\n * (4 - 1)}:{\rer}) edge node [left] {a} ({360/4 - 360/\n * (4 - 1)}:\radius-\margin-\rd);
\path
({360/4 + 360/\n * (2 - 1)}:{\rer}) edge node [left] {a} ({360/4 + 360/\n * (2 - 1)}:\radius-\margin-\rd);

\def \alph {360/4 - 360/\n * (5 - 1)}
\foreach \s in {1,...,\N}
{
\path 
({\alph -(360-\alph)/\N *\s}:{\rer}) edge [white,text=black,anchor=south,sloped] node [] {\dots\dots} ({\alph -(360-\alph)/\N *\s}:\radius-\margin-\rd);
}

\path 
({360/4 + 360/\n * (4 - 1)}:{\rer}) edge [white,text=black,anchor=south,sloped] node [] {\dots \dots} ({360/4 + 360/\n * (4 - 1)}:\radius-\margin-\rd);
\end{tikzpicture}
\end{figure}


\end{document}

但结果很糟糕——这些点不对称,而且它们的角度似乎不对。有什么想法可以让我美化它吗? 在此处输入图片描述

谢谢!

答案1

接下来你会看到两个选项,第一个是Matsmath建议的,第二个红色的是我的。你可以选择。

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
\centering
\caption{Star Graph}
\begin{tikzpicture}
\label{star_poa}
\def \n {20}
\def \N {8}
\def \radius {3cm}
\def \rd {1mm}
\def \rer {4mm}

\def \margin {8} % margin in angles, depends on the radius

\node[draw, circle] at (360:0mm) (ustar) {$u_*$};
\foreach \i [count=\ni from 0] in {t,1,2,3,4}{
  \node[draw, circle] at ({108-\ni*18}:\radius) (u\ni) {$u_{\i}$};
  \node at ({115-\ni*18}:\radius/2) {a};
  \draw (ustar)--(u\ni);
}

\foreach \i in {1,3,...,11}{
  \node[circle] at ({-\i*18}:\radius) (aux) {\phantom{$u_{5}$}};
  \draw[dotted, shorten >=3mm, shorten <=3mm] (ustar)--(aux);
}

\draw[dotted,red] (18:\radius/2) arc[start angle=18, end angle=-226, radius=\radius/2];
\end{tikzpicture}
\end{figure}
\end{document}

答案2

运行xelatex

\documentclass[pstricks]{standalone} 
\usepackage{pst-node,multido}
\begin{document}[![enter image description here][1]][1]
\degrees[16]\psset{radius=4mm}
\begin{pspicture}(-3.5,-3.5)(3.5,3.5)
\Cnodeput(0,0){u}{$u_*$}\Cnodeput(3;5){ut}{$u_t$}\ncline{u}{ut}\naput{a}
\multido{\iA=1+1,\iB=4+-1}{4}{%
    \Cnodeput(3;\iB){u\iA}{$U_\iA$}%
    \ncline{u}{u\iA}\naput{a}}
\multido{\iA=6+1}{11}{%
    \pnode(3;\iA){u\iA}\ncline[linestyle=dotted,nodesepB=2mm]{u}{u\iA}}
\end{pspicture}

\end{document}

如果您愿意运行,pdflatex则使用包auto-pst-pdf和选项-shell-escape

\documentclass{article} 
\usepackage{auto-pst-pdf}
\usepackage{pst-node,multido}
\begin{document}
\degrees[16]\psset{radius=4mm}
\begin{pspicture}(-3.5,-3.5)(3.5,3.5)
    \Cnodeput(0,0){u}{$u_*$}\Cnodeput(3;5){ut}{$u_t$}\ncline{u}{ut}\naput{a}
    \multido{\iA=1+1,\iB=4+-1}{4}{%
        \Cnodeput(3;\iB){u\iA}{$U_\iA$}%
        \ncline{u}{u\iA}\naput{a}}
    \multido{\iA=6+1}{11}{%
        \pnode(3;\iA){u\iA}\ncline[linestyle=dotted,nodesepB=2mm]{u}{u\iA}}
\end{pspicture}

\end{document}

命令行如下所示:

pdflatex --shell-escape <file>

在此处输入图片描述

相关内容