pgf-pie:如何改变方形饼图中的文本位置?

pgf-pie:如何改变方形饼图中的文本位置?

有没有办法,移动左下角的文字;
换句话说:如何破解软件包的默认设置 pgf-pie.sty

请注意,我使用的是虚构的百分比值。

女朋友

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgf-pie}

\begin{document}
\begin{tikzpicture}[xscale = 1.75, 
 font=\sffamily,
mystyle/.style={draw=white, very thick, text=white, font=\sffamily\bfseries},
]
\pie[square,  
style={mystyle},
color={yellow!80!orange, gray, blue!40, orange}, 
%text=inside,
text=legend, 
]{68/A, 22/B, 5/C, 5/D}
\end {tikzpicture}

\end{document}

答案1

这是一条评论,而不是答案:使用普通的 tikz 可以轻松进行微调和灵活性。恕我直言,破解不太灵活的软件包会浪费时间。

下面我给出了一些替代方案:圆形图、矩形图和条形图(太简单了!)。需要进行一些简单的计算。

圆形图表 在此处输入图片描述

\documentclass[border=5mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[line join=round,font=\sffamily]
\def\r{2}
\pgfmathsetmacro{\a}{5/100*360} % a=18
\pgfmathsetmacro{\b}{22/100*360}
\pgfmathsetmacro{\c}{68/100*360}
\fill[yellow!80!orange,draw=white] (0,0) circle(\r);
\fill[orange,draw=white] (0,0)--+(0:\r) arc(0:-\a:\r)--cycle;
\fill[blue!40,draw=white] (0,0)--+(0:\r) arc(0:\a:\r)--cycle;
\fill[gray,draw=white] (0,0)--+(-\a:\r) arc(-\a:-\a-\b:\r)--cycle;
\path[white]
(\a/2:.8*\r) node[scale=.6]{$5\%$}
(-\a/2:.8*\r) node[scale=.6]{$5\%$}
(-\a-\b/2:.6*\r) node[scale=.8]{$22\%$}
(\a+\c/2:.5*\r) node{$68\%$};
\def\s{.25} \def\t{.15}
\path[sq/.pic={\fill (-\t,-\t) rectangle(\t,\t);}] 
(1.5*\r,3*\s) pic[yellow!80!orange]{sq} node[right=1.5mm]{A}
(1.5*\r,\s) pic[gray]{sq} node[right=1.5mm]{B}
(1.5*\r,-\s) pic[blue!40]{sq} node[right=1.5mm]{C}
(1.5*\r,-3*\s) pic[orange]{sq} node[right=1.5mm]{D};
\end{tikzpicture}
\end{document}

矩形图如果您坚持使用矩形图,您可以进行类似的操作。

在此处输入图片描述

\begin{tikzpicture}[font=\sffamily]
\fill[blue!40,draw=white] (0,0) rectangle +(1,1) ;
\fill[orange,draw=white] (1,0) rectangle +(1,1);
\pgfmathsetmacro{\b}{11/5}
\fill[gray,draw=white] (0,0) rectangle +(2,-\b);
\pgfmathsetmacro{\c}{17/4}
\fill[yellow!80!orange,draw=white] (0,1) rectangle (-\c,-\b);

\path[white] 
(0,0) node[above right,scale=.6]{$5\%$}
(1,0) node[above right,scale=.6]{$5\%$}
(0,-\b) node[above right,scale=.8]{$22\%$}
(-\c,-\b) node[above right]{$68\%$};

\path[sq/.pic={\fill (-\t,-\t) rectangle(\t,\t);}] 
(current bounding box.east)++(0:1)
+(90:3*\s) pic[yellow!80!orange]{sq} node[right=1.5mm]{A}
+(90:\s) pic[gray]{sq} node[right=1.5mm]{B}
+(-90:\s) pic[blue!40]{sq} node[right=1.5mm]{C}
+(-90:3*\s) pic[orange]{sq} node[right=1.5mm]{D};
\end{tikzpicture}

条形图这是最简单的一个。

在此处输入图片描述

\begin{tikzpicture}[font=\sffamily,line width=10mm]
\draw[yellow!80!orange] (0,0) rectangle ++(0:6.8) coordinate (A);
\draw[gray] (A) rectangle ++(0:2.2) coordinate (B);
\draw[blue!40] (B) rectangle ++(0:.5) coordinate (C);
\draw[orange] (C) rectangle ++(0:.5) coordinate (D);

\path[every node/.style={midway}] (0,0)
--(A) node[above]{$68\%$} node[below]{A}
--(B) node[above]{$22\%$} node[below]{B}
--(C) node[above]{$5\%$}  node[below]{C}
--(D) node[above]{$5\%$}  node[below]{D};
\end{tikzpicture}

相关内容