表格中的 Tikz 图形

表格中的 Tikz 图形

这是我的代码:

\documentclass{article}
\usepackage{fullpage}
\usepackage{pgf-pie}
\usepackage{tabularx}

\usetikzlibrary{decorations.text}
\usepackage{ifthen}


\begin{document}



\begin{table}[ht]
%\caption{Multi-column and multi-row table}
\begin{center}
\begin{tabular}{|p{1.5cm}|>{\centering}p{2.5cm}|>{\centering}p{1.5cm}|>{\raggedleft}p{3cm}|} %{|c|c|c|c|}
    \hline
    Protocol1 & protocol2 & protocol3 \tabularnewline
    \hline
    \multicolumn{1}{|c|}{Speed varies between 5 and 35} 
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{8.3/B1, 33.3/B2, 58.3/B3}
    \end{scope}  
    \end{tikzpicture}}  
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture}} 
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{20.2/B1, 35.5/B2, 44.2/B3}
    \end{scope}  
    \end{tikzpicture}} \\
    \hline
    \multicolumn{1}{|c|}{Speed varies between 5 and 45} 
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{6.6/B1, 33.3/B2, 60/B3}
    \end{scope}  
    \end{tikzpicture}}  
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture}} 
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{19.8/B1, 35.6/B2, 44.4/B3}
    \end{scope}  
    \end{tikzpicture}} \\
    \hline
    \multicolumn{1}{|c|}{Speed varies between 5 and 65} 
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{4.7/B1, 33.3/B2, 61.9/B3}
    \end{scope}  
    \end{tikzpicture}}  
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture}} 
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{19.3/B1, 35.8/B2, 44.7/B3}
    \end{scope}  
    \end{tikzpicture}} \\
    \hline
    \multicolumn{1}{|c|}{Speed varies between 5 and 85} 
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{3.7/B1, 33.3/B2, 62.9/B3}
    \end{scope}  
    \end{tikzpicture}}  
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture}} 
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \multicolumn{1}{|c|}{\begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{19/B1, 36.9/B2, 44.9/B3}
    \end{scope}  
    \end{tikzpicture}} \\
    \hline

\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}



\end{document}

示例图

我想删除第 5 列并删除第一列中的标题协议,然后按照图添加 p-1、p-2 和 p-3

答案1

您需要&分隔同一行中的单元格。

\documentclass[margin=1]{standalone}
\usepackage{fullpage}
\usepackage{pgf-pie}
\usepackage{tabularx}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\usepackage{ifthen}
\begin{document}
\begin{tabular}{|c|c|c|c|}
    \hline
    & Protocol1 & protocol2 & protocol3 \tabularnewline
    \hline
    {Speed varies between 5 and 35} &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{8.3/B1, 33.3/B2, 58.3/B3}
    \end{scope}  
    \end{tikzpicture}  &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture} &
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{20.2/B1, 35.5/B2, 44.2/B3}
    \end{scope}  
    \end{tikzpicture} \\
    \hline
    {Speed varies between 5 and 45} &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{6.6/B1, 33.3/B2, 60/B3}
    \end{scope}  
    \end{tikzpicture}  &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture} &
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{19.8/B1, 35.6/B2, 44.4/B3}
    \end{scope}  
    \end{tikzpicture} \\
    \hline
    {Speed varies between 5 and 65} &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{4.7/B1, 33.3/B2, 61.9/B3}
    \end{scope}  
    \end{tikzpicture}  &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture} &
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{19.3/B1, 35.8/B2, 44.7/B3}
    \end{scope}  
    \end{tikzpicture} \\
    \hline
    {Speed varies between 5 and 85} &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{3.7/B1, 33.3/B2, 62.9/B3}
    \end{scope}  
    \end{tikzpicture}  &
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{33.3/B1, 33.3/B2,33.3/B3}
    \end{scope}  
    \end{tikzpicture} &
    %\multirow{1}{*}{Multi-col-row}}&X\\
    \begin{tikzpicture}[font=\scriptsize]
    \begin{scope}[scale=.4,xshift=.5cm]
    \pie[explode=0.2]{19/B1, 36.9/B2, 44.9/B3}
    \end{scope}  
    \end{tikzpicture} \\
    \hline
\end{tabular}
\end{document}

在此处输入图片描述

答案2

要将文本放在中间,请使用m{...}列类型。

请注意,就您而言,这些scope环境是无用的。

我已经添加\useasboundingbox (-5,-5) rectangle (5,5);,以便所有饼图都有相同的边界框并且它们的中心正确对齐。

另请参阅何时应使用 \begin{center} 而不是 \centering?

在此处输入图片描述

相关内容