About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Smile for the Camera: a new cybercrime short story ebook.


12.2.2 The pgf-pie Package

The pgf-pie package [116] is available on MiKTeX, but not on TeX Live. For most of this book (and for the series, in general) I have chosen packages that are available on both distributions, but as there's so little choice in this topic, this section describes the pgf-pie package. If you are a TeX Live user, you will need to manually install the package as follows:

  1. Download http://mirror.ctan.org/graphics/pgf/contrib/pgf-pie.zip
  2. Unpack the pgf-pie.zip archive.
  3. Copy pgf-pie.sty to somewhere on TeX's path.
  4. Copy the manual pgf-pie-manual.pdf to somewhere on texdoc's path.
For example, on Linux:

unzip pgf-pie.zip
mkdir -p ~/texmf/tex/latex/pgf-pie
cp pgf-pie/pgf-pie.sty ~/texmf/tex/latex/pgf-pie/
mkdir -p ~/texmf/doc/latex/pgf-pie
cp pgf-pie/pgf-pie-manual.pdf ~/texmf/doc/latex/pgf-pie/

You can use kpsewhich to check that the package has been successfully installed:

kpsewhich pgf-pie.sty

This should display the full path to pgf-pie.sty if the file is on TeX's path otherwise it displays nothing.

The pgf-pie package provides just one command:

\pie[options]{list}

which should be placed inside the tikzpicture environment. The ⟨list⟩ argument should be a comma-separated list of values in the form ⟨number/text⟩ where ⟨number⟩ is the value and ⟨text⟩ is the outer label for the segment.

The optional argument ⟨options⟩ is a key=value list where the following keys are available:

pos
Sets the centre of the chart to the value {x⟩,⟨y}. The default is the origin.

rotate
Rotates the chart by the given number of degrees.

radius
Sets the radius of the chart. The default is 3.

color
Sets the colours for each segment. The value should be a comma-separated list of colours corresponding to each segment or a single colour, which indicates the colour for the entire chart.

explode
Offset the segments. The value may be a single number, in which case all segments are offset by that amount, or the value may be a comma-separated list of numbers where each value is the offset amount for the corresponding segment.

sum
The sum of all the data. This can be calculated automatically if the auto option is set. The default is 100. If the auto option is off and the actual data sum is less that this value there will be a missing segment in the chart.

auto
A boolean key. If true, the sum of the data is calculated automatically.

after number
Indicates the text to place after the number shown in the segment. The default is \%.

before number
Indicates the text to place before the number shown in the segment.

scale font
A boolean key. If true, this scales the font used for the inner label according to the size of the segment, so large segments will have large inner labels and small segments will have small inner labels.

text
Indicates how to position the text (outer label). The value may be one of: label (place the text label outside the segment), pin (as label but also draws a line from the segment arc to the label), inside (place the text label inside the segment above the value) or legend (create a legend). The default is label.

There are some other options as well. See the manual [116] for further details.

Example 61. A Pie Chart (pgf-pie package)

This example has trivial labels A, …, E and uses the optional argument to change some of the pie chart settings. Note that the pgf-pie package automatically loads tikz.

\documentclass{article}

\usepackage{pgf-pie}

\begin{document}

\begin{tikzpicture}
\pie[explode={0,0.5,0,0.75,0},% offset segments 2 and 4
  color={yellow,cyan,green,pink,orange},% segment colour 
  text=legend% create a legend
 ]% settings
 {5/A,10/B,15/C,30/D,40/E}% values and labels
\end{tikzpicture}

\end{document}

This produces the chart shown in Figure 12.7.

Figure 12.7: An Example Pie Chart (pgf-pie package)
 
Image of pie chart with five segments. Each segment has a percentage written inside it.

Segment 1 (yellow fill colour): 5%.
Segment 2 (cyan fill colour): 10%.
Segment 3 (green fill colour): 15%.
Segment 4 (pink fill colour): 30%.
Segment 5 (orange fill colour): 40%.

To the right of the pie chart is a legend where each row has a small filled square with a black border with text next to it.

[yellow square] A
[cyan square] B
[green square] C
[pink square] D
[orange square] E

End of Image.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs