3

I'm trying to create a star graph in Latex. My graph may have an arbitrary large number of vertices, so I'm trying to incorporate this fact in the drawing. This is what I have done so far:

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

But it turns out pretty bad - the dots aren't symmetric, and their angle seems to be out of place. Any idea on how I can prettify it? enter image description here

Thanks!

3
  • Why is pretty bad? What do you expect? Could you make your question less opinion-based?
    – Ignasi
    Commented Jun 2, 2016 at 13:52
  • hi, I edited the post Commented Jun 2, 2016 at 13:56
  • You can try to replace the dots with (white) graph-nodes having dashed edges.
    – Matsmath
    Commented Jun 2, 2016 at 14:13

2 Answers 2

4

Following you'll find two options, the first is based in Matsmath suggestion, the second in red is mine. You can choose.

enter image description here

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

run with 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}

if you prefer to run pdflatex then use package auto-pst-pdf and option -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}

the comman line looks like:

pdflatex --shell-escape <file>

enter image description here

4
  • Your code does not seem to compile :( (not a package issue) Commented Jun 5, 2016 at 6:33
  • sure, it does compile.
    – user2478
    Commented Jun 7, 2016 at 20:14
  • It took me a while to figure that you said it is xelatex...any idea on how it can be included into latex file? Commented Jun 15, 2016 at 12:04
  • see my edited answer if you prefer to run pdflatex
    – user2478
    Commented Jun 15, 2016 at 12:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .