I'm trying to align these three pie charts, side by side, and to have the same legend for the three but with a title for each. But the changes that I have done, didn't work. This is my code:
\documentclass[oneside,12pt]{scrbook} %scrbook has more options than article
\usepackage{tikz}
\usepackage{pgf-pie}
\usepackage{pgfplots}
\usepackage{bchart}
\usepackage{tikz,stackengine}
\def\stackalignment{r}
\setstackgap{S}{2pt}
\begin{document}
\newcounter{a}
\newcounter{b}
\def\stackalignment{r}
\newcommand\pielabelon[3][0pt]{%
\abovebaseline[#3]{#2%
\makebox[-\dimexpr8pt+#1]{\smash{%
\stackunder{}{\rule{1pt}{\dimexpr#3+2.5ex}}}}}
}
\newcommand\pielabelunder[3][0pt]{%
\belowbaseline[#3]{#2%
\makebox[-\dimexpr8pt+#1]{\smash{%
\stackon{\rule{0pt}{1.3ex}}{\rule{1pt}{\dimexpr#3+2.5ex}}}}}
}
\newcommand{\slice}[4]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
% slice
\draw[thick,fill=black!10] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;
% outer label
\node[label=\midangle:#4] at (\midangle:1) {};
% inner label
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
\pgfmathparse{max(\temp,-0.5) + 0.8}
\let\innerpos\pgfmathresult
\node at (\midangle:\innerpos) {#3};
}
\begin{figure} [!htbp]
\begin{center}
\begin{tikzpicture}[scale=3]
\newcounter{e}
\newcounter{f}
\foreach \p/\t in {
31/Cash,
69/Private Equities}
{
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\slice{\thea/100*360}
{\theb/100*360}
{\ifnum\p>3\relax\p\%\fi}{\t}
}
\end{tikzpicture}
\end{center}
\caption{Alocation of the amount invested in each sub-asset class}
\label{fi2}
\end{figure}
\begin{figure} [!htbp]
\begin{center}
\begin{tikzpicture}[scale=3]
\newcounter{g}
\newcounter{h}
\foreach \p/\t in {
45/Absolute Return Bonds,
45/Emerging Market Debt,
7/Private Equities,
3/Property (3\%)}
{
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\slice{\thea/100*360}
{\theb/100*360}
{\ifnum\p>3\relax\p\%\fi}{\t}
}
\end{tikzpicture}
\end{center}
\caption{Alocation of the amount invested in each sub-asset class}
\label{fi2}
\end{figure}
\begin{figure} [!htbp]
\begin{center}
\begin{tikzpicture}[scale=3]
\newcounter{i}
\newcounter{j}
\foreach \p/\t in {
61/Absolute Return Bonds,
20/Emerging Market Debt,
5/Private Equities,
10/Property,
4/Hedge Funds}
{
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\slice{\thea/100*360}
{\theb/100*360}
{\ifnum\p>3\relax\p\%\fi}{\t}
}
\end{tikzpicture}
\end{center}
\caption{Alocation of the amount invested in each sub-asset class}
\label{fi2}
\end{figure}
\end{document}
thanks in advance.