TeX - LaTeX Asked by BigDinosaur on December 6, 2020
Is there a fast way to add a central vertex connected to all others after drawing the cycle graph using the graph library of the tikz package?
This is what the code currently looks like:
documentclass{article}
begin{document}
usepackage{tikz}
usetikzlibrary{graphs,graphs.standard}
begin{tikzpicture}[scale=0.8,every node/.style={scale=0.8}]
graph [nodes={circle,fill=black!25}, edges={black!60, semithick}, clockwise, radius=8em,
n=9, p=0.3]
{ subgraph C_n [n=6,m=3,clockwise,radius=2cm] };
end{tikzpicture}
end{document}
Give a name to subgraph
and then you can use the vertices. Finally find the center of subgraph
and draw from center to each vertices.
documentclass[tikz,margin=3mm]{standalone}
usetikzlibrary{graphs,graphs.standard,calc}
begin{document}
begin{tikzpicture}[scale=0.8,every node/.style={scale=0.8}]
graph [nodes={circle,fill=black!25}, edges={black!60, semithick}, clockwise, radius=8em,
n=9, p=0.3]
{ subgraph C_n [n=6,m=3,clockwise,radius=2cm,name=A] };
node at ($(A 1)!.5!(A 4)$) (C){};
foreach i in {1,2,...,6}{
draw (C)-- (A i); }
draw [fill=black!25](C) circle (0.4em);
end{tikzpicture}
end{document}
ADDENDUM:
According to pgf manual on page 212, you can use mid
definition.
documentclass[tikz,margin=3mm]{standalone}
usetikzlibrary{graphs,graphs.standard,calc}
begin{document}
begin{tikzpicture}[scale=0.8,every node/.style={scale=0.8}]
graph [empty nodes, nodes={circle,fill=black!25}, edges={black!60, semithick}, clockwise, radius=8em,
n=9, p=0.3]
{ subgraph C_n [n=6,m=3,clockwise,radius=2cm,name=A]-- mid};
node at ($(A 1)!.5!(A 4)$) (C){1};
foreach i [count=xi from 2] in {1,2,...,6}{
node at (A i){xi}; }
end{tikzpicture}
end{document}
Correct answer by ferahfeza on December 6, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP