3

I have a pgf-pie chart and some of the values are so small that the number does not display correctly. Therefore I would like to put them outside of the chart, as seen on the second picture I found on the internet.

MWE of my chart

\documentclass[tikz, 12pt, a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[usenames, dvipsnames, rgb]{xcolor}
\usepackage{tikz}
\usepackage{pgf-pie}
\usetikzlibrary{arrows, positioning, shadows}
\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
\pie[sum=auto,text=legend]{10/A, 1/B, 29/C, 43/D, 16/E}
\end{tikzpicture}
\caption{Pie}
\end{figure}
\end{document}

This is what my chart looks like

My pie

This is the picture of how I imagine my the numbers outside could look like I found but obviously, I'd like to keep the legend and all other formatting.

The other chart

How can that be done?

  • If you believe the duplicate answer I cited does not address your situation, let me know I can label your question as not a duplicate. – Steven B. Segletes May 03 '21 at 15:32
  • @StevenB.Segletes It is very similar but the solution given in the question you mentioned doesn't really work well with absolute (non-percentage) values – ccvbdfbfdbfb May 03 '21 at 15:32

1 Answers1

3

I'm learning pgf-pie as I go, and adapted from my answer here, Put percentages outside of pie chart. But in this case, I had to learn to use the sum= qualifier to specify charts with a total other than 100. That was especially important here, because the method I used was to superimpose 3 pie charts: the first chart plots all 5 slices with one label arrangement, the second plot superimposes 2 slices with a different label arrangement, and the last plot does a single slice with another labeling arrangement.

\documentclass[tikz, 12pt, a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[usenames, dvipsnames, rgb]{xcolor}
\usepackage{tikz}
\usepackage{pgf-pie}
\usetikzlibrary{arrows, positioning, shadows}
\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
\pie[sum=auto,text=legend]{10/A, 1/B, 29/C, 43/D, 16/E}
% COMMENT EDIT: 10+1+29+43+16 = 99 !!!
\pie[sum=99, hide number]{10/, 1/1}
\pie[sum=99]{10/}
\end{tikzpicture}
\caption{Pie}
\end{figure}
\end{document}

enter image description here

  • that's smart! thanks – ccvbdfbfdbfb May 03 '21 at 16:11
  • Nice solution. I wondered why you used sum=99 instead of sum=100 and I noticed a weird gap when using a sum of 100. Did you find this by try and error, or is it a logical reason to do so? – SebGlav May 03 '21 at 17:30
  • 1
    @SebGlav 10+1+29+43+16 = 99. The weird gap was caused because the the first chart's pies were 10/99 and 1/99 fractions. If you set sum=100 on subsequent chart, then the slices were .1 and .01 fractions. – Steven B. Segletes May 03 '21 at 17:33
  • Wow! And I'm a math teacher! I didn't even think about summing all the figures, and thought it was percentages... Sorry for the dumb question. So you could have used sum=99 instead of sum=auto in the first pie (I tried, obviously). Anyway, nice answer. – SebGlav May 03 '21 at 17:36
  • 1
    @SebGlav I fell down the same hole, until I realized that sum= could take something other than auto. Don't feel bad. It would have been more obvious if the totals summed to something quite distinct, like 42. – Steven B. Segletes May 03 '21 at 17:37