我正在使用 pgf-pie 软件包,并希望两个饼图彼此相邻但使用相同的图例。如何才能使图例位于两个图表下方的中央?
迷你示例:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{center}
\begin{minipage}{.45\textwidth}
\begin{tikzpicture}
\tikzset{lines/.style={draw=white},}
\pie[color={viola, rosso, giallo, blu, verde},sum=auto, after number=,text=legend,every only number node/.style={text=black},style={lines}]{10/A,20/B,30/C,10/D}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tikzpicture}
\tikzset{lines/.style={draw=white},}
\pie[color={viola, rosso, giallo, blu, verde},sum=auto, after number=,text=legend,every only number node/.style={text=black},style={lines}]{10/A,20/B,30/C,10/D}
\end{tikzpicture}
\end{minipage}
\end{center}
\end{document}
此示例并排绘制了两个饼图,但每个饼图都有一个图例。
答案1
根据pgf-pie
文档中,您可以使用pos
选项将 放置pie
在 内部tikzpicture
。您不需要minipage
。
而且从示例中可以看出,值列表 ( 10/A, 20/B
) 中的第二个参数似乎会将名称添加到饼图中。如果您不想要第二个图例,请编写一个名称为空的值列表。如果顺序正确,则将使用第一个图例。
\documentclass[border=10pt]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}
\tikzset{lines/.style={draw=white},}
\pie[color={purple, red, yellow, blue, green},sum=auto, after number=,text=legend,every only number node/.style={text=black},style={lines}]{10/A,20/B,30/C,10/D}
\pie[pos={8,0},color={purple, red, yellow, blue, green},sum=auto, after number=,every only number node/.style={text=black},style={lines}]{10/,20/,30/,10/}
\end{tikzpicture}
\end{document}
答案2
使用subfigure
包。我没有pgf-pie
包,所以我无法测试它,但是此代码应该可以工作:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgf-pie}
\begin{document}
\begin{center}
\begin{figure*}[t!]
\centering
\begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}
\tikzset{lines/.style={draw=white},}
\pie[color={viola, rosso, giallo, blu, verde},sum=auto, after number=,text=legend,every only number node/.style={text=black},style={lines}]{10/A,20/B,30/C,10/D}
\end{tikzpicture}
\end{subfigure}%
~
\begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}
\tikzset{lines/.style={draw=white},}
\pie[color={viola, rosso, giallo, blu, verde},sum=auto, after number=,text=legend,every only number node/.style={text=black},style={lines}]{10/A,20/B,30/C,10/D}
\end{tikzpicture}
\end{subfigure}
\caption{Caption place holder}
\end{figure*}
\end{center}
\end{document}