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.

1
  • 1
    Please edit to provide something we can compile - that's much more useful than a mere fragment.
    – cfr
    Mar 3, 2018 at 5:16

1 Answer 1

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

3
  • 1
    Why should this be a comment? It looks like an answer to me (assuming it does what you say - I didn't check).
    – cfr
    Mar 3, 2018 at 5:17
  • 1
    @cfr I did check, see the image. (Also, commenting should now be possible.) Mar 3, 2018 at 6:35
  • 1
    Thanks for adding the image. You are right, I removed the unnecessary initial comment. Mar 3, 2018 at 10:20

You must log in to answer this question.

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