0

I am using pgf-pie to create pie charts. Usually, the number is written into the slices. I would like to replace the number by another string and the same time keep the description pinned.

   \begin{tikzpicture}
    \pie[ 
        /tikz/every pin/.style={align=left},
        sum=auto,
        radius=2,
        text=pin,
        rotate=120 ,
        % before number=\phantom,
        %  after number=,
        color={red!70,blue!70}
        ]{
        14.850/$\textbf{Not supported}$\\ (59.7\%),
        10.009/$\textbf{Supported}$\\ (40.3\%)
        }
\end{tikzpicture}

So Instead 14.850 I want 14850 and instead 10.009 I want 10009.

Is that possible?

Thanks Amit

1 Answer 1

1

Update: pgf-pie has renamed some internals. The following MWE works for the version on Github dated December 26th 2020 (https://github.com/pgf-tikz/pgf-pie). The original code below still works for the version currently on CTAN (May 2020).

\documentclass{article}
\usepackage{pgf-pie}
\usepackage{xstring}
\makeatletter
\renewcommand{\pgfpie@numbertext}[1]
{
  \pgfpie@ifhidenumber{}{%
  \pgfpie@beforenumber\StrSubstitute{#1}{.}{}\pgfpie@afternumber%
  }
}
\makeatother
\begin{document}
   \begin{tikzpicture}
    \pie[ 
        /tikz/every pin/.style={align=left},
        sum=auto,
        radius=2,
        text=pin,
        rotate=120 ,
        color={red!70,blue!70}
        ]{
        14.850/\textbf{Not supported}\\(59.7\%),
        10.009/\textbf{Supported}\\ (40.3\%)
        }
\end{tikzpicture}
\end{document}

For the question as asked after the edit (print the original label without the dot) a quick workaround can be used by redefining \pgfpie@numbertext, which is the internal macro in pgf-pie that prints the numbers. With the xstring package you can substitute the dot for the empty string. The code below is for an older version of pgf-pie (May 2020).

MWE:

\documentclass{article}
\usepackage{pgf-pie}
\usepackage{xstring}
\makeatletter
\renewcommand{\pgfpie@numbertext}[1]
{
  \ifhidenumber
  \else
  \pgfpie@beforenumber\StrSubstitute{#1}{.}{}\pgfpie@afternumber
  \fi
}
\makeatother
\begin{document}
   \begin{tikzpicture}
    \pie[ 
        /tikz/every pin/.style={align=left},
        sum=auto,
        radius=2,
        text=pin,
        rotate=120 ,
        color={red!70,blue!70}
        ]{
        14.850/\textbf{Not supported}\\(59.7\%),
        10.009/\textbf{Supported}\\ (40.3\%)
        }
\end{tikzpicture}
\end{document}

Result:

enter image description here


Original answer:

To replace the number with the label you can use a combination of hide number and text=inside. Note that because the text is relatively long it does not fit inside the slices in the default (centered) position of the number. You can push the text a bit down for the left slice by introducing some vertical space with \vspace. This needs to be negative, and for some reason it should be specified in the second line and not the first.

MWE:

\documentclass{article}
\usepackage{pgf-pie}
\begin{document}
   \begin{tikzpicture}
    \pie[ 
        /tikz/every pin/.style={align=left},
        sum=auto,
        radius=2,
        hide number,
        text=inside,
        rotate=120 ,
        % before number=\phantom,
        %  after number=,
        color={red!70,blue!70}
        ]{
        14.850/\textbf{Not supported}\\\vspace{-10mm}(59.7\%),
        10.009/\textbf{Supported}\\ (40.3\%)
        }
\end{tikzpicture}
\end{document}

Result:

enter image description here

5
  • Thanks, I would like leave the description pinned outside and replace the number 14.850 by 14850. I can't write large numbers because then I get "dimension too large"
    – Amit
    Oct 17, 2020 at 16:28
  • @Amit I see, that was not clear to me from your question. I'll have to think about an approach for that problem.
    – Marijn
    Oct 17, 2020 at 16:31
  • Thanks, I edit the question.
    – Amit
    Oct 17, 2020 at 16:33
  • @Amit I added a workaround for the clarified question.
    – Marijn
    Oct 17, 2020 at 17:03
  • thanks for help. It works fine. I found also another workaround but your solution is much more elegant.
    – Amit
    Oct 17, 2020 at 18:14

You must log in to answer this question.

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