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.

At this address Label Points in a circle in tikz you can see the code to divide a circle into x cells. How to write a phrase into each cell of the divided circle?

share|improve this question
1  
Could you elaborate or provide a mockup of what you want? For example, how do you want the phrases to be placed and formatted within the cells? –  N.N. Oct 24 '11 at 13:41
add comment

3 Answers 3

Here is the modified output from my answer that prints an item in each of the circle segments. The following code uses a purely pstricks solution with psforeach. pstricks provides an internal list counter \psLoopIndex, used to identify the current indexed item:

enter image description here

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\usepackage{multido}% http://ctan.org/pkg/multido
\begin{document}

\begin{pspicture}(10,10)
  \SpecialCoor
  \psset{unit=3cm,runit=3cm}% Scaling of x,y and r units
  \pnode(3,0){O}% Circle origin
  \pscircle(O){1}% Outer circle
  \degrees[20]% 20 angles per 360 degrees (each angle is 18 degrees)
  \rput(O){\multido{\i=1+1}{20}{% Cycle through 20 angles and relocate relative to circle origin
    \pcline(O)(1;\i)% Print line from origin to circle edge
    \uput{5pt}[\i]{\i}(1;\i){\i}% Print label with rotation
    }%
    \psforeach{\nA}{here,is,some,text,that,is,placed,around,the,circle,%
      in,a,clockwise,fashion,right,to,the,very,last,segment}{%
        \rput{0.5}{\rput[cC]{-\the\psLoopIndex}(0.7;-\the\psLoopIndex){\nA}}%
    }% Okay, actually it is counter-clockwise, but that's too large a word...
  }
\end{pspicture}
\end{document}

The following code uses a different list-processing macro \docsvlist provided by the etoolbox package. It requires a redefinition of the list item parsing macro \do, but produces the same output.

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\usepackage{multido}% http://ctan.org/pkg/multido
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\begin{document}

\begin{pspicture}(10,10)
  \SpecialCoor
  \psset{unit=3cm,runit=3cm}% Scaling of x,y and r units
  \pnode(3,0){O}% Circle origin
  \pscircle(O){1}% Outer circle
  \degrees[20]% 20 angles per 360 degrees (each angle is 18 degrees)
  \rput(O){\multido{\i=1+1}{20}{% Cycle through 20 angles and relocate relative to circle origin
    \pcline(O)(1;\i)% Print line from origin to circle edge
    \uput{5pt}[\i]{\i}(1;\i){\i}% Print label with rotation
    }%
    \newcounter{itemlist}%
    \renewcommand*{\do}[1]{%
      \rput{0.5}{\rput[cC]{-\theitemlist}(0.7;-\theitemlist){#1}}%
      \stepcounter{itemlist}% move to next item
    }
    \docsvlist{here,is,some,text,that,is,placed,around,the,circle,%
      in,a,clockwise,fashion,right,to,the,very,last,segment}% Okay, actually it is counter-clockwise, but that's too large a word...
  }
\end{pspicture}
\end{document}
share|improve this answer
    
that's counterclockwise. –  Bruno Le Floch Oct 24 '11 at 20:07
    
Yikes! But counter-clockwise would be a bit big to fit in that small a pie-piece, I admit. –  Werner Oct 24 '11 at 20:08
    
Easy: reverse the direction. –  Bruno Le Floch Oct 24 '11 at 23:52
    
Okay, you twisted my arm. :) –  Werner Oct 25 '11 at 7:55
add comment

@wh1t3 was sure faster (by a tiny bit) ;) and my solution is very similar (I also built on the code posted at the link in the question), but mine differs in that you can pass the array of text as an argument:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}

\newcommand{\TikZFractionalCake}[6]{% Num, Denom, Color, Borders, Size, Text array
\pgfmathsetmacro{\angle}{360/#2};%
\foreach[count=\x] \mytext in {#6}%
{   \pgfmathsetmacro{\lox}{\x-1}%
    \filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
    \pgfmathsetmacro{\mix}{\x-0.5}%
    \node[rotate=\mix*\angle] at (\mix*\angle:#5*0.5+0.3) {\mytext};
}
}   

\begin{document}

\begin{tikzpicture}
\TikZFractionalCake{10}{10}{white}{black}{3}{{some},{text},{you},{wanted},{to},{insert},{7},{8},{9},{10}}
\end{tikzpicture}

\end{document}

You may not that it is not necessary to have the text array elements (separated by commas) between braces, unless they contain commas. Also, if the number of text elements is less than the actual number of pie slices, the 'empty' slices will not be drawn.

enter image description here

EDIT: To wrap the text according to the size of the pie chart, the last line of the \foreach loop can be modified to:

\node[text width=#5cm*.9,align=center,rotate=\mix*\angle] at (\mix*\angle:#5*0.5+0.3) {\mytext};

The multiplier *.9 is inserted to avoid the text wedging in in the center of the pieslice. (This of course will not correct the situation where the slice is physically too small for the text one tries to squeeze in.)

share|improve this answer
    
With this I can write only one word. What I would like to do is to write a sentence like (Thank you very much) –  Nicolas Oct 24 '11 at 14:22
    
That's funny, I can write into the slices full sentences... ;) like this: \TikZFractionalCake{10}{10}{white}{black}{5}{{Thank you very much},{text},{you},{wanted},{to},{insert},{7},{8},{9},{10}}. You might need to increase the diameter (argument 5) to accommodate all the sentence. –  Count Zero Oct 24 '11 at 14:35
    
Sorry for that. Another question : How I can fill color for each cell ? –  Nicolas Oct 24 '11 at 16:51
    
How instead of increasing the diameter (argument 5) we wrap the text. So the text is written not only on one line but on multiple lines. –  Nicolas Oct 24 '11 at 16:59
    
@Nicolas: For wrapping the text, check the EDIT of my answer. As for the colors: you really don't like to read the code you get, don't you? What if someone posted a code that steals your credit card number, eh? Would you just run it without the blink of an eye, hm? –  Count Zero Oct 24 '11 at 18:32
show 4 more comments

If we take the solution from Tom to the question you linked, we can easily extend it to do what you want.

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}

\newcommand{\TikZFractionalCake}[5]{% Num, Denom, Color, Borders, Size
    \pgfmathsetmacro{\angle}{360/#2};%
    \foreach \x in {1,...,#1}%
    {   \pgfmathsetmacro{\lox}{\x-1}%
        \filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
        \pgfmathsetmacro{\mix}{\x-0.5}%
        \node[rotate=\mix*\angle] at (\mix*\angle:#5*0.5+.3) {phrase};
        \node[rotate=\mix*\angle] at (\mix*\angle:#5+0.3) {\x};
    }
}   

\begin{document}

\begin{tikzpicture}
\TikZFractionalCake{20}{20}{white}{black}{3}
\end{tikzpicture}

\end{document}

We use the exact same construct to place the numbers at the end to draw some text into the slices, So we place the node not at the end of the arc, but halfway between the center of the circle and the arc. All that is added is this line:

\node[rotate=\mix*\angle] at (\mix*\angle:#5*0.5+.3) {phrase};

You can play around with the rotation and the precise positioning to get exactly what you want.

The output looks like this:

Pie with phrases

Update If you want to add different phrases, the code needs to be modified a little bit, since you now need to keep track of two things in the for loop (the count and the phrase). You can do this as follows:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}

\newcommand{\TikZFractionalCake}[5]{% Num, Denom, Color, Borders, Size
    \pgfmathsetmacro{\angle}{360/#2};%
    \foreach [count=\x] \p in {list, of, different, words, that, should, be, enough, to, fill, the, pieces, of, the, pie, else, it, stops, early, {:(}}%
    {   \pgfmathsetmacro{\lox}{\x-1}%
        \filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
        \pgfmathsetmacro{\mix}{\x-0.5}%
        \node[rotate=\mix*\angle] at (\mix*\angle:#5*0.5+.3) {phrase};
        \node[rotate=\mix*\angle] at (\mix*\angle:#5+0.3) {\x};
    }
}   

\begin{document}

\begin{tikzpicture}
\TikZFractionalCake{20}{20}{white}{black}{3}
\end{tikzpicture}

\end{document}

Which looks like this:

Pie with different phrases

share|improve this answer
    
This add the word phrase in each cell. What I would like to do is to write different sentences in each cell. –  Nicolas Oct 24 '11 at 14:15
2  
That's going the wrong way! Seriously, I couldn't work out what the sentence was because I assumed that each word followed in the rough downward direction from the previous one. –  Loop Space Oct 24 '11 at 17:50
    
@AndrewStacey Come on man, they're even numbered :P That being said, the sentence sounds horrible. Should be otherwise, not else... –  Roelof Spijker Oct 24 '11 at 18:23
1  
They aren't even numbered. They're oddly numbered. The presence of the words meant that I didn't notice the numbers until I'd worked out the direction of the sentence. Then I saw the numbers. Strange how ones brain works ... –  Loop Space Oct 24 '11 at 18:26
add comment

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.