Pie charts with LaTeX TikZ

Define a new command to insert a pie slice:


  % slice
  \draw[thick,fill=black!10] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;

  % outer label
  \node[label=\midangle:#4] at (\midangle:1) {};

  % inner label
  \pgfmathparse{max(\temp,-0.5) + 0.8}
  \node at (\midangle:\innerpos) {#3};

Then define the slices in the order you want to have them and with the percentages and labels. You can start at a different point in the circle by setting the counter ‘d’ to a different value before the loop, e.g. \setcounter{d}{25}.

\foreach \p/\t in {66/, 17/Equative, 10/Difference, 7/}
          { \small \p\%}{\t}
  \node[label=0.5:Ranked] at (1,0.6) {};
  \node[label=0.5:Superlative] at (1,-0.3) {};

I didn’t like the automatic placement of two labels, that is why I gave ‘Ranked’ and ‘Superlative’ an empty label in the loop and placed them by hand later on.

The original is from Texample, uploaded by Robert Vollmert.

This entry was posted in LaTeX and tagged , , , by swk. Bookmark the permalink.

About swk

I am a software developr, data scientist, computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.