Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm sure it's very easy: I want to draw a circle and at specific, equally spaced angles display some words. So I can draw the circle as curved arrows using a \foreach. How can I use the same \foreach to take words I want to display from a list of words? Here is some code (which I didn't make, but found in texexample.net)

\def \n {12}
\def \radius {4cm}
\def \margin {9} 

\foreach \s in {1,...,\n}
{
  \node at ({360/\n * (\s - 1)}:\radius) {\s};
  \draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius) 
  arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
    }
 \end{tikzpicture}
\end{document}

Now, instead of the{\s}, which displays numbers at the nodes, I'd like it to display words.

share|improve this question

3 Answers 3

up vote 7 down vote accepted

I don't exactly know what your workflow requires but there is more than one way of doing such figure. Following your example, one way is to create an additional text array and pick elements from it.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\textarray{{"this","is","a","array","but","it","is","not","the","array","however","also"}}
\def \n {12}
\def \radius {4cm}
\def \margin {9} 

\foreach \s in {1,...,\n}
{
  \node at ({360/\n * (\s - 1)}:\radius) {\pgfmathparse{\textarray[\s-1]}\pgfmathresult};
  \draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius) 
  arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
    }
 \end{tikzpicture}
\end{document}

enter image description here

You can add the rotation etc. properties to the nodes with extra options just as you have computed the locations. Also you might want to read the text decorations in the manual.

share|improve this answer
1  
a array is of course an array. I was testing the spellchecker :p –  percusse Aug 8 '12 at 15:53
    
exactly. Thanks a lot! ... (just, I'd like some of those words to be mathematical objects, which renders an error, how could I fix it?) –  c.p. Aug 8 '12 at 16:42
    
I mean, using commands like "\mathbb{R}" and so on, doesn't work. –  c.p. Aug 8 '12 at 17:07
    
@JorgeCampos You can use it with "$\noexpand\mathbb{R}$", it's a little inconvenient but required to stall the expansion a little (amsfonts package is required for \mathbb{}) –  percusse Aug 8 '12 at 17:19
    
Wonderful! thank you very much! –  c.p. Aug 8 '12 at 17:27

You could also define a list which contains the increment number and the word to be placed at that position via:

\newcommand{\WordList}{1/one, 2/two, 3/three, 4/four, 5/five, 6/six, 7/seven, 8/eight, 9/nine}

to yield:

enter image description here

Notes:

  • In this specific case percusse's answers is clearly better, but this might be useful in other similar situations.

Code:

\documentclass{standalone}
\usepackage{tikz}

\newcommand{\WordList}{1/one, 2/two, 3/three, 4/four, 5/five, 6/six, 7/seven, 8/eight, 9/nine}
\def\n{9}
\def \radius {4cm}
\def \margin {9} 

\begin{document}
\begin{tikzpicture}

\foreach \s/\word in \WordList {
  \node at ({360/\n * (\s - 1)}:\radius) {\word};
  \draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius) 
  arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\end{tikzpicture}
\end{document}
\end{document}
share|improve this answer

This is just a small improvement to Peter Grill's solution: you may use \foreach \x [count=\s] in {text}, that way the number of the iteration is saved in \s and you can specify the texts as a comma separated list:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\begin{document}

\def \n {10}
\def \radius {4cm}
\def \margin {9} 

\begin{tikzpicture}
\foreach \x [count=\s] in {one,two,three,four,five,six,seven,eight,nine,ten}
{
  \node at ({360/\n * (\s - 1)}:\radius) {\x};
  \draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius) 
  arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
    }
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
nice, I like this too. thank you! –  c.p. Aug 9 '12 at 14:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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