TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to have the numbers that are inside the pie chart to be in the legend. How can I make that happen?

Here is the MWE:


\pie[text=legend,style=drop shadow,radius=2]{51.3/Protestant, 23.9/Roman Catholic, 3.3/Other Christian, 1.7/Jewish, 0.7/Buddhist, 0.6/Muslim, 0.4/Hindu, 1.2/Other religions, 16.1/No religion }


I also have another pie chart, where the text is quite long. How can I set the width of the text so that it wraps around before the page ends? Here is what it looks like:

enter image description here

I forgot that PGF-PIE was not on CTAN. Here is a link to the google source: http://code.google.com/p/pgf-pie/

share|improve this question
pgf-pie isn't on CTAN, a link to where one can find it (code.google.com/p/pgf-pie I assume) would be nice. – Torbjørn T. May 3 '13 at 13:11
@TorbjørnT. Sorry about that! EDIT Link has been added to the post. – Jeel Shah May 3 '13 at 13:12
up vote 6 down vote accepted

The pgf-pie package is not as flexible as one wishes. Unfortunately, etoolbox refuses to patch, so we do it manually.

Open up (make a copy/backup) the pgf-pie.sty file and scroll to the end, there is a part enclosed in \iflegend … \fi. Replace the enclosed scope environment with:

  \begin{scope}[node distance=+0pt]
    \foreach \p/\t  [count=\i from 0] in {#2}
      \node[below=of legendpos.south west, anchor=north west, every legend entry/.try, name=legendpos] {\t\ifpienumberinlegend\legendbeforenumber\p\legendafternumber\fi};
      \node[draw, fill=\thecolor, \style, at=(legendpos.base west), anchor=south east] {};

Now you can use the number in legend style (which should come after before number and after number!).

For long legend entries, you can use the every legend entry style, say

every legend entry/.append style={text width=2cm}

The setup now allows this (the node distance is set to zero as the inner ysep creates, in my opinion, enough room between the entries.

You need the positioning library for the newer below=of syntax.



\pgfkeys{/number in legend/.code=
    \csname if#1\endcsname
    /number in legend/.default=true
\begin{tikzpicture}[every legend entry/.append style={text width=2cm}]
\pie[text=legend, style=drop shadow, radius=2, before number=\ (, after number=\,\%), number in legend]{51.3/Protestant, 23.9/Roman Catholic, 3.3/Other Christian, 1.7/Jewish, 0.7/Buddhist, 0.6/Muslim, 0.4/Hindu, 1.2/Other religions, 16.1/No religion }


enter image description here

share|improve this answer
Is there alternative to the label length? Because, you are right, there isn't much difference. – Jeel Shah May 3 '13 at 14:24
@gekkostate See the updated version. – Qrrbrbirlbel May 3 '13 at 15:10
This definitely deserves a bounty! This is awesome. – Jeel Shah May 3 '13 at 17:22
Can we remove the number somehow and just use label inside the pie? – t-my Jun 9 '14 at 11:00

Your Answer


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.