TeX - LaTeX Asked on December 13, 2021
I am using pgf-pie
for simple pie-diagrams and would like to define a color scheme that is used by default for all charts. As it seems pgf-pie
does not offer styles or color lists by default, hence I tried to solve this by defining a MYpie
command that sets some standard options before applying specific settings. This works so far in my MWE:
documentclass{standalone}
usepackage{pgf-pie}
newcommand{MYpie}[2][]{pie[color={black,red,blue,orange},/tikz/draw=white,/tikz/text=white,#1]{#2}}
begin{document}
begin{tikzpicture}%[draw=white,text=white]
MYpie{10/A, 20/B, 30/C, 10/D, 10/E, 10/F, 10/G}
MYpie[pos={8,0}, square] {23/A, 27/B, 17/C, 13/D, 20/E}
MYpie[pos={2,-8}, cloud] {10/A, 20/B, 30/C, 20/D, 20/E}
end{tikzpicture}
end{document}
However there are two problems: The first is, that if I try to introduce the white text and drawing into my newcommand{MYpie}
, like I do above, then I get the text white, but not the drawn lines, if I use the %[draw=white,text=white]
instead, it works fine.
The second problem is: If my text is white, this applies to text on the pies and outside the pies, however this leads to invisible text outside the pies. So is it possible to select to different colors with pgf-pie?
The key-value scheme of pgf-pie
is ... not very flexible nor robust. Hence I patch pie
to let you use
pgfkeys{color=...}
or pie[color=...]
to specify color schemes andpie[/tikz/<key>=<value>]
to specify tikz options with scope restricted to current pie
.To achieve the desired effect, in the following example I use:
nodes={white}
to set node text in white,every label/.style={black}
to restore the label text (the text outside the pies) from white to black, since label is a subtype of node,draw=white
to set the line in white.documentclass{article}
usepackage{pgf-pie}
usepackage{xpatch}
% remove hard-coded color wheel
xpatchcmdpie
{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},}
{}
{}{fail}
% restrict the scope of pie options
xpretocmdpie{begingroup}{}{fail}
xapptocmdpie{endgroup}{}{fail}
makeatletter
% set default color wheel
defpgfpie@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}
makeatother
% set new color wheel
pgfkeys{
color={black,red,blue,orange}
}
begin{document}
tikzset{
% restricted by implementation, pie[style=...] accepts single key-value pair
pie style/.style={thick, draw=white}
}
begin{tikzpicture}[every label/.style={black}, nodes={white}]
pie[style={pie style}] {10/A, 20/B, 30/C, 10/D, 10/E, 10/F, 10/G}
% test scope
pie[
color={blue!60, cyan!60, yellow!60, orange!60},
/tikz/nodes={black},
pos={8,0},
square,
style={pie style}
] {23/A, 27/B, 17/C, 13/D, 20/E}
pie[pos={2,-8}, cloud, style={pie style}] {10/A, 20/B, 30/C, 20/D, 20/E}
end{tikzpicture}
end{document}
Answered by muzimuzhi Z on December 13, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP