我在表格环境中为两个不同的饼图创建了下图。但我无法在各自的单元格中为每个饼图添加标题。
我使用了以下代码,但只能按照图中所示添加标题。请帮忙。
\usepackage{pgf-pie}
\usepackage{tikz}
\usepackage{capt-of}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\newcommand\mycom[2]{\genfrac{}{}{0pt}{}{#1}{#2}}
\begin{document}
\setlength{\abovedisplayskip}{3pt}
\setlength{\belowdisplayskip}{3pt}
\begin{table}[h]
\centering
\begin{tabular}{|l|l|}
\hline
\begin{tikzpicture}[scale=0.75,line join=round]
\pie [rotate = 180]
{57/A,
5/B,
3/C,
9/D,
3/E,
22/F,
1/G}
\end{tikzpicture}
&
\begin{tikzpicture}[scale=0.75,line join=round]
\pie [rotate = 180]
{60/A,
5/B,
2/C,
10/D,
2/E,
20/F,
1/G}
\end{tikzpicture}
\\ \hline
\end{tabular}
\captionof{figure}{Pie Chart}
\label{samples}
\end{table}
\end{document}
答案1
你可以使用subcaption
包。而且没有必要table
仅仅因为使用了tabular
内部就使用环境。
\documentclass{article}
\usepackage{array}
\usepackage{pgf-pie}
\usepackage{subcaption}
\begin{document}
\setlength{\abovedisplayskip}{3pt}
\setlength{\belowdisplayskip}{3pt}
\begin{figure}[h]
\centering
\begin{tabular}{|W{c}{0.45\textwidth}|W{c}{0.45\textwidth}|}
\hline
\begin{subfigure}[b]{0.44\linewidth}
\centering
\begin{tikzpicture}[scale=0.75,line join=round]
\pie [rotate = 180]
{57/A,
5/B,
3/C,
9/D,
3/E,
22/F,
1/G}
\end{tikzpicture}
\caption{A pie chart.}
\end{subfigure}
&
\begin{subfigure}[b]{0.44\linewidth}
\centering
\begin{tikzpicture}[scale=0.75,line join=round]
\pie [rotate = 180]
{60/A,
5/B,
2/C,
10/D,
2/E,
20/F,
1/G}
\end{tikzpicture}
\caption{Another pie chart.}
\end{subfigure}
\\ \hline
\end{tabular}
\caption{Pie charts.}
\label{samples}
\end{figure}
\end{document}