在 LaTeX beamer 模板中包含饼图

在 LaTeX beamer 模板中包含饼图

我想在 LaTeX beamer 模板中绘制饼图,但是出现了错误。

代码如下:

\usepackage[utf8]{inputenc}
\usepackage{pgf-pie}
\usepackage{xcolor}

 \begin{frame}{complicated family structure}
\begin{tikzpicture}[scale=0.8]
\def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
#2\printnumbertrue
\else
\printnumberfalse
\fi}
\newif\ifprintnumber
\pie[rotate=40,radius=4,color={black!30, black!40, black!50, black!60,black!70,red!80},before number=\printonlylargeenough{90},
    after number=\ifprintnumber\%\fi]{3.3/, 3.1/, 1.2/Others, 1.1/,1.0/,90.3/Didi}
 
\end{tikzpicture}
\end{frame}

我不知道为什么会发生这种情况,因为当我在普通模板中绘制饼图时,没有发生任何错误。

在此处输入图片描述

答案1

我认为您只需要添加[fragile]作为frame选项。

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{pgf-pie}
\usepackage{xcolor}
\begin{document}
\begin{frame}[fragile]{Complicated family structure}
\begin{tikzpicture}[scale=0.8]
\def\printonlylargeenough#1#2{\unless\ifdim#2pt<#1pt\relax
#2\printnumbertrue
\else
\printnumberfalse
\fi}
\newif\ifprintnumber
\pie[rotate=40,radius=4,color={black!30, black!40, black!50, black!60,black!70,red!80},before number=\printonlylargeenough{90},
    after number=\ifprintnumber\%\fi]{3.3/, 3.1/, 1.2/Others, 1.1/,1.0/,90.3/Didi};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容