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:
- Download http://mirror.ctan.org/graphics/pgf/contrib/pgf-pie.zip
- Unpack the pgf-pie.zip archive.
- Copy pgf-pie.sty to somewhere on TeX's path.
- Copy the manual pgf-pie-manual.pdf to somewhere on texdoc's path.
$ 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:
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:
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 theauto
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
(aslabel
but also draws a line from the segment arc to the label),inside
(place the text label inside the segment above the value) orlegend
(create a legend). The default islabel
.
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.
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).