4

I have a similar question to this, but am hoping to find a more systematic answer.

This is my code--

     \documentclass[tikz,border=5]{standalone}
     \usetikzlibrary{graphs}
     \usetikzlibrary{graphs.standard}
     \begin{document}
     \begin{tikzpicture}[every node/.style={fill,circle,very thick}]
       \graph [clockwise] {
         subgraph C_n [n=5,name=A, radius=1cm]; 
         subgraph I_n [n=5,name=B, radius=2cm];

         };

     \end{tikzpicture}
     \end{document}

c5

I am trying to connect the vertices from Cn to In systematically with /foreach, with something like:

     \documentclass[tikz,border=5]{standalone}
     \usetikzlibrary{graphs}
     \usetikzlibrary{graphs.standard}
     \begin{document}
     \begin{tikzpicture}[every node/.style={fill,circle,very thick}]
       \graph [clockwise] {
         subgraph C_n [n=5,name=A, radius=1cm]; 
         subgraph I_n [n=5,name=B, radius=2cm];

         \foreach \i in {1,...,5} \draw (A \i) -- (B \i);
         };

     \end{tikzpicture}
     \end{document}

I've tried a few iterations of this code, and haven't been able to find something that will compile. Hoping for something systematic so that I can build graphs with larger n than 5. Thanks in advance for your help.

Kati
  • 41
  • 1
    Please edit to provide something we can compile - that's much more useful than a mere fragment. – cfr Mar 03 '18 at 05:16

1 Answers1

8

Moving your \foreach outside the \graph works as I suppose you would like.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}
\begin{document}
\begin{tikzpicture}[every node/.style={fill,circle,very thick}]
  \graph [clockwise] {
    subgraph C_n [n=5,name=A, radius=1cm]; 
    subgraph I_n [n=5,name=B, radius=2cm];
};

\foreach \i in {1,...,5} \draw (A \i) -- (B \i);

\end{tikzpicture}
\end{document}

Result

Axel Krypton
  • 1,083