饼图的副标题

饼图的副标题

有人能帮我用以下代码在每个 Pi 图表顶部写副标题吗?请参阅示例图片在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{pgf-pie} % version: https://github.com/pgf-tikz/pgf-pie Dec 26, 2020
\usepackage{etoolbox}
\makeatletter
\pretocmd{\pgfpie@slice}{% define label text with percentages for small values
\pgfmathparse{#3 > 5}%
\ifnum\pgfmathresult=1 %
\def\txtlabel{#4}% original label for large values
\else%
\def\txtlabel{#4 (#3\%)}% label with percentage for small values
\fi%
}{\message{define label patch ok}}{\message{define label patch failed}}

\patchcmd{\pgfpie@slice}% use label text instead of original argument #4
{\pgfpie@text={\pgfpie@midangle:#4}}%
{\pgfpie@text={\pgfpie@midangle:\txtlabel}}%
{\message{add pct patch ok}}%
{\message{add pct patch failed}}%

\def\pgfpie@numbertext#1{% don't print percentage in slice for small values
  \pgfpie@ifhidenumber{}{%
    \pgfmathparse{#1 > 5}%
    \ifnum\pgfmathresult=1 %
    \pgfpie@beforenumber#1\pgfpie@afternumber%
    \fi
  }%
}
\makeatother
\begin{document}
\begin{subfigure}
\footnotesize
\begin{tikzpicture}
%\begin{scope}[scale=0.7]
\pie[before number =, after number = {\%},text=pin, ]{
18.9/1-20 Employees,
29.2/21-100 Employees,
22.6/101-500 Employees,
7.5/501-1000 Employees,
21.7/Over 1000 Employees
}
%\end{scope}
\end{tikzpicture}
\end{subfigure}

%\begin{tikzpicture}
%\pie[before number =, after number = {\%},text=pin, ]{
%42.3/ Combination of DDD and business capability,
%29.8/ Only business capability,
%27.9/ only DDD
%}
%\end{tikzpicture}
\begin{subfigure}
\footnotesize
\begin{tikzpicture}
%\begin{scope}[scale=0.7]
\pie[before number =, after number = {\%},text=pin, ]{
5.7/1 Practitioners,
43.4/2-3 Practitioners,
27.4/4-5 Practitioners,
9.4/6-7 Practitioners,
6/8-10 Practitioners,
8.5/Over 10 Practitioners
}
%\end{scope}
\end{tikzpicture}
\end{subfigure}
\end{document}

答案1

正如我在评论中所说,你可以使用subcaption包来为不同的子图添加标题。如果你将正文放在图像前面,它将出现在顶部。因此:

\documentclass{article}
\usepackage{pgf-pie} % version: https://github.com/pgf-tikz/pgf-pie Dec 26, 2020
\usepackage{etoolbox}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikzscale}

\begin{document}
\begin{figure}
\begin{subfigure}{0.4\textwidth}
\caption{Caption Over Here}
\footnotesize
\begin{tikzpicture}[scale=0.7]
\pie[before number =, after number = {\%},text=pin, ]{
18.9/1-20 Employees,
29.2/21-100 Employees,
22.6/101-500 Employees,
7.5/501-1000 Employees,
21.7/Over 1000 Employees
}
\end{tikzpicture}
\end{subfigure}
\hfill
\begin{subfigure}{0.4\textwidth}
\caption{Caption Over There}
\footnotesize
\begin{tikzpicture}[scale=0.7]
\pie[before number =, after number = {\%},text=pin, ]{
5.7/1 Practitioners,
43.4/2-3 Practitioners,
27.4/4-5 Practitioners,
9.4/6-7 Practitioners,
6/8-10 Practitioners,
8.5/Over 10 Practitioners
}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}

注意:我清理了你的 MWE 以便它可以编译:主要是 - 我将独立文件更改为文章,以便你的子图可以放入图中。

相关内容