Iterate over colors on next pie chart with pgf-pie

This is a slight variation of gigi's answer, whose code I am using. It is less manual, but it redefines things from the pgf-pie package (which does not come with TeXLive, as it seems). You need to issue \pgfpiecolorsync in order to continue the color in the next pie.

\documentclass{article}
\usepackage{pgf-pie}
\newcounter{piecolor}
\newcounter{piemaxcolor}
\makeatletter
\renewcommand{\pgfpie@findColor}[1]
{
  \pgfmathparse{int(mod(#1+\number\value{piecolor},\value{pgfpie@colorLength}))}
  \let\ci\pgfmathresult
  \setcounter{piemaxcolor}{\ci}
  \foreach \c [count=\j from 0] in \color {
    \ifnum \j=\ci
    \xdef\thecolor{\c}
    \thecolor
    \breakforeach
    \fi
  }
}  
\newcommand{\pgfpiecolorsync}{\setcounter{piecolor}{\value{piemaxcolor}\stepcounter{piecolor}}}
\newcommand{\pgfpiecolorreset}{\setcounter{piecolor}{0}}
\makeatother
\begin{document}

\begin{tikzpicture}
    \pie{58.54/A, 39.02/B, 2.44/C}
    \pgfpiecolorsync
\end{tikzpicture}
\begin{tikzpicture}
    \pie{87.8/A, 12.2/B}
    \pgfpiecolorsync
\end{tikzpicture}

\begin{tikzpicture}
    \pie{58.54/A, 39.02/B, 2.44/C}
    \pgfpiecolorsync
\end{tikzpicture}
\begin{tikzpicture}
    \pie{87.8/A, 12.2/B}
    \pgfpiecolorsync
\end{tikzpicture}

\end{document}

enter image description here


A manual approach: remove the first n colors from this list:

\documentclass{article}
\usepackage{pgf-pie}

\begin{document}

\begin{tikzpicture}
    \pie{58.54/A, 39.02/B, 2.44/C}
\end{tikzpicture}



Some text.


\begin{tikzpicture}
    \pie[color={
%    blue!60, cyan!60, yellow!60,
          orange!60, red!60,
          blue!60!cyan!60, cyan!60!yellow!60, red!60!cyan!60,
          red!60!blue!60, orange!60!cyan!60}]{87.8/A, 12.2/B}
\end{tikzpicture}


\end{document}

enter image description here

Tags:

Pgf Pie