3

When I take the plot from this question Parameterizing color in \addplot and try to incorporate it into a Beamer presentation, the PDF generates, but there are lots of errors.

Am I missing anything that is requried to make the plot compatible with 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}

Errors:

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.
ajeh
  • 2,572

1 Answers1

4

It works within a fragile frame \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}

enter image description here