1
\newcommand{\slice}[4]{
  \pgfmathparse{0.5*#1+0.5*#2}
  \let\midangle\pgfmathresult

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

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

  % inner label
  \pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
  \let\temp\pgfmathresult
  \pgfmathparse{max(\temp,-0.5) + 0.8}
  \let\innerpos\pgfmathresult
  \node at (\midangle:\innerpos) {#3};
}

\begin{tikzpicture}[scale=3]

\newcounter{a}
\newcounter{b}
\foreach \p/\t in {1/Below 20, 59/21-30, 40/30 and above}
  {
    \setcounter{a}{\value{b}}
    \addtocounter{b}{\p}
    \slice{\thea/100*360}
          {\theb/100*360}
          {\p\%}{\t}
  }

\end{tikzpicture}
1
  • 2
    Could you please add a compilable code?
    – user156344
    Commented Apr 2, 2019 at 7:07

1 Answer 1

3

First of all welcome to TeX.SE and please add a compilable MWE, so that we can help you fully. However, I could achieve it with

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgf-pie}
\begin{document}
    \begin{tikzpicture}
    \pie{10.1/ , 20.8/ , 29.1/ , 40/}
    \end{tikzpicture}
\end{document}

to get:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .