1

I have the following code and would like to set the legend below both subfigures in the centre. It would also be great to have subcaption (a) to be positioned horizontally with the corresponding pie.

I found: How to put small numbers outside the pie slices without making a mess. But I don't know how to transfer this idea to my case.

Thank you so much for your help!

\documentclass[a4paper]{scrreprt}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgf-pie}
\begin{document}
\begin{center}
\begin{figure}
    \centering
    \begin{subfigure}[b]{0.35\textwidth}
        \begin{tikzpicture}[scale=.85]
        \tikzset{lines/.style={draw=black},}
        \pie[color={gray,gray!50,gray!20},text=pin,sum=auto, after number=\%,style={lines},rotate=3.5,explode={0, 0, 0.5}]{85.8/Voters,12/Inactive,2.2/}
        \end{tikzpicture}
        \subcaption{Overall structure}
    \end{subfigure}\hfill
    \begin{subfigure}[b]{0.35\textwidth}
        \begin{tikzpicture}[scale=.85]
        \tikzset{lines/.style={draw=white},}
        \pie[sum=2.2, after number=\%,text=legend,every only number node/.style={text=black},style={lines}]{.4/Hyperactives,.1/Soc. Med. Opposers,.6/Apathetic Members,.3/Financiers,.2/Interested Sustainers,.3/Analog Activists,.3/Informed Members}
        \end{tikzpicture}
        \subcaption{Affiliation clusters}
    \end{subfigure}
    \caption{Overview of party affiliation}
\end{figure}
\end{center}
\end{document}

enter image description here

Pullp
  • 113
  • Your example has the desired property as you want. what is your problem really? –  Jan 27 '20 at 11:36
  • well, when I compile it, it does not have the legend below the figure, but on right side. – Pullp Jan 27 '20 at 12:01

1 Answers1

2

The wheelchart package, which I wrote, can be used.

In the first \wheelchart, the third slice is shifted with the key explode{3}.

The colors are specified with a list using the key WClistcolorsA. These colors can be used with the macro \WClistcolorsA. The percentage is obtained with \WCperc.

In the second \wheelchart, the gap is obtained with the key gap.

The legend is determined by the key legend. This is a tabular which is placed in a \node. The rows are determined by the key legend row. The result of all rows can be obtained with \WClegend.

The percentages in the slices are obtained with the key wheel data.

enter image description here

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\pgfkeys{
  /wheelchart,
  counterclockwise,
  perc precision=1,
  radius={0}{2},
  start angle=0
}
\wheelchart[
  at={(-3,0)},
  explode{3}=0.5,
  lines=\WCvarB*0.5,
  slices style={
    \WClistcolorsA,
    draw=black
  },
  WClistcolorsA={gray,gray!50,gray!20},
  wheel data=\WCperc
]{%
  85.8/1/Voters,
  12/1/Inactive,
  2.2/0/%
}
\wheelchart[
  at={(3,0)},
  data=,
  gap=0.02,
  legend row={\tikz\fill[\WClistcolorsB] (0,0) rectangle (0.3,0.3); & \WCvarB},
  legend={
    \node[anchor=north] at (-3,-2.5) {%
      \begin{tabular}{l@{ }l}%
      \WClegend%
      \end{tabular}%
    };
  },
  slices style=\WClistcolorsB,
  WClistcolorsB={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},
  wheel data=\qty{\WCvarA}{\percent}
]{%
  .4/Hyperactives,
  .1/Soc. Med. Opposers,
  .6/Apathetic Members,
  .3/Financiers,
  .2/Interested Sustainers,
  .3/Analog Activists,
  .3/Informed Members%
}
\end{tikzpicture}
\end{document}
matexmatics
  • 4,819