EDITED to provide true \frac
capability, all using the native keys provided by the pgf-pie
package. Three versions are shown:
\frac
\displaystyle\frac
, and
#1/#2
First thing, is the fraction has to be provided in braces as {a/b}
, so that tikz
can evaluate it for calculating the pie-slice size. Then, in order to get the label as a \frac
, one uses before number
and after number
keys to basically unpack and evaluate the fraction not as a math calculation, but rather as math typesetting.
I figured out this solution by looking at the guts of the pgf-pie
package and realized that the macros \beforenumber
and \afternumber
were part of the typesetting. I, therefore, had to figure out how to define the keys to expand what I needed expanded, in order to evaluate \beforenumber\p\afternumber
as, for example, \frac{1}{6}
, when \p
is defined as {1/6}
.
The MWE:
\documentclass[fleqn,12pt, a4paper]{scrartcl}
\usepackage{tikz}
\usepackage{pgf-pie}
\def\myfrac#1{\expandafter\expandafter\expandafter\expandafter\expandafter%
\expandafter\expandafter\myfracaux\expandafter\expandafter\expandafter#1}
\def\myfracaux#1/#2\relax{$\piestyle\frac{#1}{#2}$}
\def\piestyle{\textstyle}
\begin{document}
\begin{tikzpicture}
%%I want 1/6 instead of 1 inside the pieces:
\pie[sum=auto, before number=\myfrac, after number=\relax]
{{1/2}/,{3/16}/,{1/4}/,{1/16}/}
\end{tikzpicture}
%
\def\piestyle{\displaystyle}
\begin{tikzpicture}
%%I want 1/6 instead of 1 inside the pieces:
\pie[sum=auto, before number=\myfrac, after number=\relax]
{{1/6}/,{1/6}/,{1/6}/,{1/6}/,{1/6}/,{1/6}/}
\end{tikzpicture}
\begin{tikzpicture}
%%I want 1/6 instead of 1 inside the pieces:
\pie[sum=auto]
{{1/6}/,{1/6}/,{1/6}/,{1/6}/,{1/6}/,{1/6}/}
\end{tikzpicture}
\end{document}
