3

I have created a primary version of a pentagon network with the following code:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=black,minimum size=.2cm,inner sep=0pt,anchor=center},
d/.style={draw,circle,fill=white,minimum size=.5cm,inner sep=0pt, anchor=center}}
\begin{tikzpicture}[font=\large]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
    \node (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){$R_\x$};
}

\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\end{tikzpicture}
\end{document}

enter image description here

I would like to improve the network in the following aspects:

1) Position those node labels inside the circles;

2) Label each connection at an appropriate location with a label $y_{ij}$, where i and j are the indices of the two associated nodes;

3) Color two particular connecting lines and their labels, for example, $y_{23}$ and $y_{35}$, in red.

Thank you!

  • 1
    You already draw these nice circles, what is wrong with just inserting the text there? \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){$R_\x$}; And the replace the draw in the second loop by \draw (poly\Ncorners-\X) -- node[midway,auto]{$y_{\X\Y}$} (poly\Ncorners-\Y); – user121799 Aug 29 '18 at 20:50
  • @marmot Many thanks! How about the other two improvements? – bluepole Aug 29 '18 at 20:54
2

This is at best a temporary answer. The problems is that the figure is small so the labels are jammed.

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric,backgrounds}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=black,minimum size=.2cm,inner sep=0pt,anchor=center},
d/.style={draw,circle,fill=white,minimum size=.5cm,inner sep=0pt, anchor=center}}
\begin{tikzpicture}[font=\large]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){$R_\x$};
}
\foreach\X [evaluate=\X as \NextX using {int(\X+1)}]in {1,...,\Ncorners}{
\ifnum\NextX<6
 \foreach\Y in {\NextX,...,\Ncorners}{
 \pgfmathtruncatemacro{\Ztest}{10*\X+\Y}
 \ifnum\Ztest=23
  \colorlet{mycolor}{red}
 \else
  \ifnum\Ztest=35
   \colorlet{mycolor}{red}
  \else
   \colorlet{mycolor}{black}
  \fi
 \fi
 \draw[color=mycolor] (poly\Ncorners-\X) -- node[midway,fill=white,font=\tiny,sloped,inner
 sep=0.2pt]{$y_{\X\Y}$} (poly\Ncorners-\Y);
 }
\fi
}
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks a lot! How to adjust the figure size so that the labels would look nicer? – bluepole Aug 29 '18 at 21:30
  • 1
    @bluepole The sizes of the polygons are determined by the minimum size key, Just increase them a bit and then you may drop font=\tiny in the label node. This is a matter of taste, so please just play with these values. (Of course, there are two minimum sizes. – user121799 Aug 29 '18 at 21:37
  • All good now. Thanks again for the great help! – bluepole Aug 29 '18 at 21:41
2

For fun, a short code with pstricks:

\documentclass[border=12pt, svgnames]{standalone}

\usepackage{pst-poly}
\usepackage{auto-pst-pdf}

\begin{document}

\psset{unit=3.5cm, dimen=middle, linejoin=1, linewidth=1.2pt}
\begin{pspicture}(-1,-1)(1,1)
    \providecommand{\PstPolygonNode}{\psdots[dotsize=16pt, linecolor=Lavender!75 ](1;\INode)}
    \rput{72}(0,0){\PstPentagon[PolyName=R] }
    \rput(0,0){\PstPentagon[PolyName=A, PolyOffset=2] }
    \foreach \i in {1,2,3,4,5} {\rput(R\i){$R_{\i}$}}
    \psset{linestyle=none, nrot =:U}
    \foreach\i/\j in {1/4,1/5,2/4,2/5,3/4,3/5,4/5}{\ncline{R\i}{R\j}\ncput{\colorbox{white}{$y_{\i\j}$}}}
    \ncline{R2}{R1}\ncput{\colorbox{white}{$y_{12}$}}
    \psset{linestyle=solid, linewidth=1.25pt, linecolor=Tomato, nodesep=8pt}
    \foreach \i/\j in {2/3,3/5} {\ncline{R\i}{R\j}\ncput{\colorbox{white}{\color{Tomato}$y_{\i\j}$}}}
\end{pspicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.