pgfplots 命名的图例与 beamer 讲义不兼容?

pgfplots 命名的图例与 beamer 讲义不兼容?

请考虑:

\documentclass[12pt,t, fleqn, 
    %,handout %% "handout" for one page per slide 
]{beamer} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}

\begin{document}

\begin{frame}
    \frametitle{title}

    \begin{tikzpicture}[
        ]
        \begin{axis}[
                xmin=0, xmax=11, 
                ymin=-10, ymax=10, domain=0:10,
                axis x line = center, 
                axis y line = center,
                axis line style = {thick, gray},
                xlabel = {$t$},
                every axis x label/.append style = {below, gray},
                ylabel = {$y(t)$},
                legend style={at={(1.1,1)}, anchor=north west, nodes=right, name=leg},
                clip mode = individual,
            ]
            \only<+->{
                \addplot+ [smooth, mark=none] {2*x-10};
                \addlegendentry{one};
            }
            \only<+->{
                \addplot+ [smooth, mark=none] {5*sin(deg(x))};
                \addlegendentry{two};
            }
            \only<+->{
                \node at (leg.south) [below=10pt, align=center,draw]
                    {$\Uparrow$ \\ \textbf{THIS}};
            }
        \end{axis}
    \end{tikzpicture}   
\end{frame}
\end{document}

这给出了三张幻灯片的预期序列:

幻灯片的正确顺序

其中最后一个节点出现在图例下方。如果我取消%, handout注释标题中的行,则会出现此错误:

/home/romano/tmp/testleg.tex|44 error| Package pgf Error: No shape named leg is known.

相应标签放错了位置:

讲义输出中的错误节点

我该如何避免这个问题?我尝试了 和 的各种组合fragile以及 的规范<+|handout=1>,但无济于事。

答案1

正如概述这里,您只能在轴环境之外添加相对于图例的节点leg。这是示例的副本,但进行了微小更改:

\documentclass[12pt,t, fleqn, 
%handout %% "handout" for one page per slide 
]{beamer} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}

\begin{document}

    \begin{frame}
        \frametitle{title}

        \begin{tikzpicture}[]
        \begin{axis}[
        xmin=0, xmax=11, 
        ymin=-10, ymax=10, domain=0:10,
        axis x line = center, 
        axis y line = center,
        axis line style = {thick, gray},
        xlabel = {$t$},
        every axis x label/.append style = {below, gray},
        ylabel = {$y(t)$},
        legend style={at={(1.1,1)}, anchor=north west, nodes=right, name=leg},
        clip mode = individual,
        ]
        \only<+->{
            \addplot+ [smooth, mark=none] {2*x-10};
            \addlegendentry{one};
        }
        \only<+->{
            \addplot+ [smooth, mark=none] {5*sin(deg(x))};
            \addlegendentry{two};
        }
        \end{axis}
        \only<+->{
            \node at (leg.south) [below=10pt, align=center,draw]
            {$\Uparrow$ \\ \textbf{THIS}};
        }
        \end{tikzpicture}   
    \end{frame}
\end{document}

答案2

看起来像是一个错误。这个 hack 解决了它。顺便说一句,frametitle 接受两个参数,而不是一个。

\documentclass[12pt,t, fleqn, 
    handout %% "handout" for one page per slide 
]{beamer} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage{pgfplots}%\pgfplotsset{compat=1.15}

\begin{document}

\begin{frame}
    \frametitle{title}{}

    \begin{tikzpicture}[
        ]
        \begin{axis}[
                xmin=0, xmax=11, 
                ymin=-10, ymax=10, domain=0:10,
                axis x line = center, 
                axis y line = center,
                axis line style = {thick, gray},
                xlabel = {$t$},
                every axis x label/.append style = {below, gray},
                ylabel = {$y(t)$},
                legend style={at={(1.1,1)}, anchor=north west, nodes=right, name=leg},
                clip mode = individual,
            ]
              \node (leg){};
               \only<+->{
                \addplot+ [smooth, mark=none] {2*x-10};
                \addlegendentry{one};
            }
            \only<+->{
                \addplot+ [smooth, mark=none] {5*sin(deg(x))};
                \addlegendentry{two};
            }
            \only<+->{
                \node at (leg.south) [below=10pt, align=center,draw]
                    {$\Uparrow$ \\ \textbf{THIS}};
            }
        \end{axis}
    \end{tikzpicture}   
\end{frame}
\end{document}

相关内容