当我从这个问题中得出情节时在 \addplot 中参数化颜色并尝试将其合并到 Beamer 演示文稿中,PDF 生成,但存在很多错误。
我是否遗漏了使情节与 Beamer 兼容所需的任何内容?
\documentclass[11pt]{beamer}
\usetheme{default}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz,pgfplots}
\usepackage{xcolor}
\usepackage{xstring}
\pgfplotsset{compat=newest}
\newcommand*{\diff}{}% Ensure it is not already defined
\newcommand*{\clr}{}% Ensure it is not already defined
\author{Me}
\title{Stuff}
\subtitle{More stuff}
\logo{Logo}
\institute{School}
\date{Today}
\subject{Math stuff}
\setbeamercovered{transparent}
\begin{document}
\maketitle
\begin{frame}
\frametitle{Multicolor chart}
\begin{tikzpicture}[font=\tiny]
\begin{axis}[
axis x line=center,
axis y line=center,
restrict y to domain=-50:50,
legend entries={$d=-2$,$d=-1$,$d=0$,$d=1$,$d=2$},legend pos=north west]%or north west, ... ,outer north east
]
\pgfplotsinvokeforeach{-2/orange, -1/red, 0/green, 1/blue, 2/brown}
{
\StrBefore{#1}{/}[\diff]%
\StrBehind{#1}{/}[\clr]%
\edef\AddPlot{\noexpand\addplot[thick,smooth,color=\clr,domain=-6:6
] {(x-\diff)^3};}%
\AddPlot
}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
错误:
line 47: Illegal parameter number in definition of \test. \end{axis}
line 47: Illegal parameter number in definition of \test. \end{axis}
line 50: Illegal parameter number in definition of \iterate. \end{frame}
line 50: Illegal parameter number in definition of \iterate. \end{frame}
line 50: Illegal parameter number in definition of \iterate. \end{frame}
line 50: Illegal parameter number in definition of \iterate. \end{frame}
line 50: Illegal parameter number in definition of \beamer@doifinframe. \end{frame}
line 50: Illegal parameter number in definition of \beamer@doifinframe. \end{frame}
line 70: Illegal parameter number in definition of \test. \end{axis}
line 70: Illegal parameter number in definition of \test. \end{axis}
line 73: Illegal parameter number in definition of \iterate. \end{frame}
line 73: Illegal parameter number in definition of \iterate. \end{frame}
line 73: Illegal parameter number in definition of \iterate. \end{frame}
line 73: Illegal parameter number in definition of \iterate. \end{frame}
line 73: Illegal parameter number in definition of \beamer@doifinframe. \end{frame}
line 73: Illegal parameter number in definition of \beamer@doifinframe. \end{frame}
line 27: Font shape `T1/cmss/m/n' in size <4> not available(Font) size <5> substituted
: Size substitutions with differences(Font) up to 1.0pt have occurred.
答案1
它在一个脆弱的框架内工作\begin{frame}[fragile]
:
\documentclass[11pt]{beamer}
\usetheme{default}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz,pgfplots}
\usepackage{xcolor}
\usepackage{xstring}
\pgfplotsset{compat=newest}
\newcommand*{\diff}{}% Ensure it is not already defined
\newcommand*{\clr}{}% Ensure it is not already defined
\author{Me}
\title{Stuff}
\subtitle{More stuff}
\logo{Logo}
\institute{School}
\date{Today}
\subject{Math stuff}
\setbeamercovered{transparent}
\begin{document}
\begin{frame}[fragile]
\frametitle{Multicolor chart}
\begin{tikzpicture}[font=\tiny]
\begin{axis}[
axis x line=center,
axis y line=center,
restrict y to domain=-50:50,
legend entries={$d=-2$,$d=-1$,$d=0$,$d=1$,$d=2$},legend pos=north west]%or north west, ... ,outer north east
]
\pgfplotsinvokeforeach{-2/orange, -1/red, 0/green, 1/blue, 2/brown}
{
\StrBefore{#1}{/}[\diff]%
\StrBehind{#1}{/}[\clr]%
\edef\AddPlot{\noexpand\addplot[thick,smooth,color=\clr,domain=-6:6
] {(x-\diff)^3};}%
\AddPlot
}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}