5

Currently, if you have two pie-charts, it will start again with color0. Is there any possibility to start with the next color (the one after used by the previous pie-chart)

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

Some text.

\begin{tikzpicture}
    \pie{87.8/A, 12.2/B}
\end{tikzpicture}

Here, the second one starts again with color0, but I want it to continue with color3

2 Answers 2

5

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

3

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

1
  • as I have at least 10 pie charts, this is not very practical
    – nee6AGag
    Commented Jun 20, 2019 at 21:01

You must log in to answer this question.

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