1

I want to have a circle of nodes in tikz, and the text in each node needs to come from an array. How do I achieve this? The following does not work.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,}
\begin{document}
\fontsize{14}{21}\selectfont
\tikzstyle{line} = [draw, -stealth, thick]
\begin{tikzpicture}[every node/.append style={circle, text height=2ex, text depth=.25ex, text width=1.5em, text centered, draw=black!80, inner sep=0pt},>=stealth',auto,thick]
\def\names{A, B, C, D, E, F, G, H}
\foreach \a in {1,2,...,8}{
\draw (\a*360/8: 4cm) node (\a) {\names[\a]};
}
\end{tikzpicture}
\end{document}
  • This is solved, sorry for the trouble. – user22209 Aug 13 '15 at 2:06
3

Eventhough you can use a two-variable loop (as you did in your answer), I'd also like to mention the possibility to work with just one variable and use the count=<macro> option (I also changed \tikzstyle for the more appropriate \tikzset):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,}

\tikzset{
  line/.style={
    draw, 
    -stealth, 
    thick
  }
}    

\begin{document}

\fontsize{14}{21}\selectfont
\begin{tikzpicture}[
  every node/.append style={
    circle, 
    text height=2ex, 
    text depth=.25ex, 
    text width=1.5em, 
    align=center, 
    draw=black!80, 
    inner sep=0pt
    },
  >=stealth',
  auto,
  thick
]
\foreach \t [count=\a] in {A,...,H}
{
  \draw (\a*360/8: 4cm) node (\a) {\t};
}
\end{tikzpicture}

\end{document}

enter image description here

0

Done with a new array.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,}
\begin{document}
\fontsize{14}{21}\selectfont
\tikzstyle{line} = [draw, -stealth, thick]
\begin{tikzpicture}[every node/.append style={circle, text height=2ex, text depth=.25ex, text width=1.5em, text centered, draw=black!80, inner sep=0pt},>=stealth',auto,thick]
\foreach \a/\t in {1/A,2/B,3/C,4/D,5/E,6/F,7/G,8/H}{
\draw (\a*360/8: 4cm) node (\a) {\t};
}
\end{tikzpicture}
\end{document}

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.