1

I have a tikzpicture with several nodes. Inside each node I am drawing a tikzpicture with something. Some nodes have charts, others have flowcharts etc.

Everything seems fine. The problem is when I put the two nodes below which have pie charts inside them. Why are the second pie chart's slice labels displaced? How can I fix that?

If I change the order of the charts, the second always displaces its labels.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\usepackage{tikz} \usepackage{pgf-pie}
\usetikzlibrary{shapes.geometric, positioning, backgrounds}

\begin{document}

\begin{figure}[htb] \centering \caption{Example of charts 1, 3, 5, and 7 - Total cost per case, activity, resource and time} \begin{tikzpicture}[align=center,node distance=.3cm and .3cm, framed] \node (c1) [label=below:Total cost per activity] {\scalebox{.9}{ \begin{tikzpicture} \pie[sum = auto, radius=2.2, color={gray!10,gray!20,gray!30,gray!40,gray!50,gray!60,gray!70,gray!80} ]{300/a,2997/b,2400/c,900/d,1800/e,2100/f,600/g,600/h} \end{tikzpicture} }}; \node (c2) [label=below:Total cost per resource, right=of c1] {\scalebox{.9}{ \begin{tikzpicture} \pie[radius=1.8, sum = auto, color={gray!10,gray!20,gray!30,gray!40,gray!50} ]{1050/Pete,1399/Sue,2100/Mike,3900/Sara,1250/Ellen} \end{tikzpicture} }}; \end{tikzpicture} \end{figure} \end{document}

enter image description here

bonk
  • 885
  • 2
    Nesting tikzpictures can cause unexpected results (see https://tex.stackexchange.com/questions/46598/problem-with-overlay-when-a-tikzpicture-is-inside-another-tikzpicture for example). However, if this is your actual picture, then you can also make it without nesting, for example using a tabular with two separate tikzpictures for the pie charts in the first row, and the two labels in the second row, and an \fbox around the tabular for the frame, among other options. – Marijn Jun 16 '21 at 14:48
  • 1
    Don't nest tikzpictures inside nodes. Use /.pic instead. – Henri Menke Jun 16 '21 at 16:05

1 Answers1

1

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

The data are given by the second variable, which is denoted by \WCvarB.

The colors of the slices are determined by the key slices style. The macro \WCcount gives the current number of the slice.

The wheel data are given by the first variable, which is denoted by \WCvarA. Their position is determined by the key wheel data pos.

The second \wheelchart is positioned with the key at.

enter image description here

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\begin{document}
\begin{tikzpicture}
\pgfkeys{
  /wheelchart,
  counterclockwise,
  data=\WCvarB,
  radius={0}{2.5},
  slices style={
    gray!\fpeval{\WCcount*10},
    draw=black
  },
  start angle=0,
  wheel data=\WCvarA,
  wheel data pos=0.8
}
\wheelchart[
  caption=Total cost per activity
]{300/a,2997/b,2400/c,900/d,1800/e,2100/f,600/g,600/h}
\wheelchart[
  at={(6,0)},
  caption=Total cost per resource
]{1050/Pete,1399/Sue,2100/Mike,3900/Sara,1250/Ellen}
\end{tikzpicture}
\end{document}
matexmatics
  • 4,819