我该如何修复这个投影仪演示错误?

我该如何修复这个投影仪演示错误?

我正在制作一个包含一些 tikzpictures 和 pgfplots 的 beamer 演示文稿,然后出现此错误:>\beamer@doifinframe 定义中的参数编号非法。我尝试添加,fragile\begin{frame}错误仍然出现,pdf 仍然会生成,但当演示文稿变大(更多 tikzpictures 和 pgfplots} 时,输出会停止。

%the error :
<to be read again> 
                   1
l.78 \end{figure}}
                  
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\pgfplotsset{width=10cm,compat=newest}






\usetheme{Warsaw}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}
\begin{document}


\begin{frame}[fragile,t]{La théorie des SVM}% \vspace{10pt}
\only<1-3>{
\begin{block}{L'hyperplan optimale}
L'hyperplan qui posséde une \alert{marge} maximale.
\end{block}}
\only<2-3>{
\begin{block}{La marge}
Deux fois la \alert{distance minimale} entre l'hyperplan et les observations.
\end{block}}

\vspace{2pt}


\only<3>{\begin{figure}
\centering
\begin{tikzpicture}[scale=0.6,marge/.style={<-,dashed,thick},
extended line/.style={shorten >=-#1,->},
extended line/.default=0.09cm]
\begin{axis}[axis background/.style={fill=gray!10},
axis line style={->},
x label style={at={(axis description cs:0.5,-0.1)},very thick,anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=-90,thick,anchor=south},clip=false,xmin=0,xmax=10,ymin=1,ymax=8,axis lines=left,scatter/classes={
a={color=blue},b={color=red}},
xlabel=$x$,
ylabel=$y$]
%scatter
\addplot+[
only marks,scatter src =explicit symbolic,
scatter,mark size=2.9pt]
coordinates{(3.67,1.47)  [b]
(6,2.5) [b]
(6.2,3) [b]
(5,2.55) [b]
(4.89,3.22) [b]
(2.8,1.5)  [b]
(2,2.071)     [b]%
(4,2)     [b]
(3.5,2.5)   [b]
(3,2)   [b]
(4.1,4.8)     [a]
(4.4,2.3)   [b]
(2.23,5.001) [a]
(2.7,4.25)  [a]
(1.5,3.35)   [a]
(1.77,3.47)   [a]
(5,4.74)     [a] %
(3.45,5)     [a]
(2,4.2)   [a]
(2.6,5.3)   [a]
(2.4,4.6)  [a]
(3.24,4.47)  [a]};
%hyperplanes
\addplot[color=red, domain=0:7.5,left]{2/5*x + 2};
\addplot[color=red, domain=7.5:7.9,left]{2/5*x + 2};
\addplot[color=red, domain=9.44:10,left]{2/5*x + 2}
node[sloped,pos=0.2](){$h(x)=0$};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 1.26};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 2.74};
%vecteur w
\node (A) at (2,2/5*2+2) {};
\node  (B) at (5,2/5*5+2) {};
\node (P) at (3.6,4.004) {};
\draw [extended line] ($(A)!(P)!(B)$) -- (P)
node[sloped,above,pos=0.6](){$w$};
%marge
\node (X) at (6,2/5*6+2.74) {};
\node  (Y) at (9,2/5*9+2.74) {};
\node (T) at (6,2/5*6+1.26) {};
\node  (Z) at (9,2/5*9+1.26) {};
\node (M) at (7.5,2/5*7.5+2) {};
\draw [marge] ($(X)!(M)!(Y)$) -- (M);
\draw [marge] ($(T)!(M)!(Z)$) -- (M);
%support vectors

\end{axis}
\end{tikzpicture}
%\caption{Hyperplan optimale}
\end{figure}}
\only<3-5>{
\begin{block}{Normalisation}
Pour les observations à limite de la marge on pose : $\arrowvert w\cdot x_{marge}+w_0\arrowvert=1$ , avec:
$\begin{cases}
 w\cdot x_{marge+}+w_0=+1 \\
\ w\cdot x_{marge-}+w_0=-1
\end{cases}$

\end{block}}

\only<5->{\begin{figure}
\centering
\begin{tikzpicture}[scale=0.6,marge/.style={<-,dashed,thick},
extended line/.style={shorten >=-#1,->},
extended line/.default=0.09cm]
\begin{axis}[axis background/.style={fill=gray!10},
axis line style={->},
x label style={at={(axis description cs:0.5,-0.1)},very thick,anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=-90,thick,anchor=south},clip=false,xmin=0,xmax=10,ymin=1,ymax=8,axis lines=left,scatter/classes={
a={color=blue},b={color=red}},
xlabel=$x$,
ylabel=$y$]
%scatter
\addplot+[
only marks,scatter src =explicit symbolic,
scatter,mark size=2.9pt]
coordinates{(3.67,1.47)  [b]
(6,2.5) [b]
(6.2,3) [b]
(5,2.55) [b]
(4.89,3.22) [b]
(2.8,1.5)  [b]
(2,2.071)     [b]%
(4,2)     [b]
(3.5,2.5)   [b]
(3,2)   [b]
(4.1,4.8)     [a]
(4.4,2.3)   [b]
(2.23,5.001) [a]
(2.7,4.25)  [a]
(1.5,3.35)   [a]
(1.77,3.47)   [a]
(5,4.74)     [a] %
(3.45,5)     [a]
(2,4.2)   [a]
(2.6,5.3)   [a]
(2.4,4.6)  [a]
(3.24,4.47)  [a]};
%hyperplanes
\addplot[color=red, domain=0:7.5,left]{2/5*x + 2};
\addplot[color=red, domain=7.5:7.9,left]{2/5*x + 2};
\addplot[color=red, domain=9.44:10,left]{2/5*x + 2}
node[sloped,pos=0.2](){$h(x)=0$};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 1.26}
node[sloped,below,pos=0.918](){$h(x)=-1$};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 2.74}
node[sloped,above,pos=0.85](){$h(x)=+1$};
%vector w
\node (A) at (2,2/5*2+2) {};
\node  (B) at (5,2/5*5+2) {};
\node (P) at (3.6,4.004) {};
\draw [extended line] ($(A)!(P)!(B)$) -- (P)
node[sloped,above,pos=0.6](){$w$};
%marge
\node (X) at (6,2/5*6+2.74) {};
\node  (Y) at (9,2/5*9+2.74) {};
\node (T) at (6,2/5*6+1.26) {};
\node  (Z) at (9,2/5*9+1.26) {};
\node (M) at (7.5,2/5*7.5+2) {};
\draw [marge] ($(X)!(M)!(Y)$) -- (M);
\draw [marge] ($(T)!(M)!(Z)$) -- (M);
%support vectors
\node (svm) at (3.5,7) {Vecteurs de support};
\node (s1) at (5,4.74) {};
\node (s2) at  (2,2.071) {};
\draw [->] (svm)--(s1);
\draw [->] (svm)--(s2);
\end{axis}
\end{tikzpicture}
%\caption{Hyperplan optimale}
\end{figure}}


\end{frame}




\end{document}



答案1

##1您可以在自定义样式中使用而不是 来修复错误#1(您需要将 加倍,#因为您在另一个宏中使用它):

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
%\usepackage{amsmath}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\pgfplotsset{width=10cm,compat=newest}

\usetheme{Warsaw}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}
\begin{document}


\begin{frame}[fragile,t]{La théorie des SVM}% \vspace{10pt}
\only<1-3>{
\begin{block}{L'hyperplan optimale}
L'hyperplan qui posséde une \alert{marge} maximale.
\end{block}}
\only<2-3>{
\begin{block}{La marge}
Deux fois la \alert{distance minimale} entre l'hyperplan et les observations.
\end{block}}

\vspace{2pt}


\only<3>{\begin{figure}
\centering
\begin{tikzpicture}[scale=0.6,marge/.style={<-,dashed,thick},
extended line/.style={shorten >=-##1,->},
extended line/.default=0.09cm]
\begin{axis}[axis background/.style={fill=gray!10},
axis line style={->},
x label style={at={(axis description cs:0.5,-0.1)},very thick,anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=-90,thick,anchor=south},clip=false,xmin=0,xmax=10,ymin=1,ymax=8,axis lines=left,scatter/classes={
a={color=blue},b={color=red}},
xlabel=$x$,
ylabel=$y$]
%scatter
\addplot+[
only marks,scatter src =explicit symbolic,
scatter,mark size=2.9pt]
coordinates{(3.67,1.47)  [b]
(6,2.5) [b]
(6.2,3) [b]
(5,2.55) [b]
(4.89,3.22) [b]
(2.8,1.5)  [b]
(2,2.071)     [b]%
(4,2)     [b]
(3.5,2.5)   [b]
(3,2)   [b]
(4.1,4.8)     [a]
(4.4,2.3)   [b]
(2.23,5.001) [a]
(2.7,4.25)  [a]
(1.5,3.35)   [a]
(1.77,3.47)   [a]
(5,4.74)     [a] %
(3.45,5)     [a]
(2,4.2)   [a]
(2.6,5.3)   [a]
(2.4,4.6)  [a]
(3.24,4.47)  [a]};
%hyperplanes
\addplot[color=red, domain=0:7.5,left]{2/5*x + 2};
\addplot[color=red, domain=7.5:7.9,left]{2/5*x + 2};
\addplot[color=red, domain=9.44:10,left]{2/5*x + 2}
node[sloped,pos=0.2](){$h(x)=0$};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 1.26};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 2.74};
%vecteur w
\node (A) at (2,2/5*2+2) {};
\node  (B) at (5,2/5*5+2) {};
\node (P) at (3.6,4.004) {};
\draw [extended line] ($(A)!(P)!(B)$) -- (P)
node[sloped,above,pos=0.6](){$w$};
%marge
\node (X) at (6,2/5*6+2.74) {};
\node  (Y) at (9,2/5*9+2.74) {};
\node (T) at (6,2/5*6+1.26) {};
\node  (Z) at (9,2/5*9+1.26) {};
\node (M) at (7.5,2/5*7.5+2) {};
\draw [marge] ($(X)!(M)!(Y)$) -- (M);
\draw [marge] ($(T)!(M)!(Z)$) -- (M);
%support vectors

\end{axis}
\end{tikzpicture}
%\caption{Hyperplan optimale}
\end{figure}}
\only<3-5>{
\begin{block}{Normalisation}
Pour les observations à limite de la marge on pose : $\arrowvert w\cdot x_{marge}+w_0\arrowvert=1$ , avec:
$\begin{cases}
 w\cdot x_{marge+}+w_0=+1 \\
\ w\cdot x_{marge-}+w_0=-1
\end{cases}$

\end{block}}

\only<5->{\begin{figure}
\centering
\begin{tikzpicture}[scale=0.6,marge/.style={<-,dashed,thick},
extended line/.style={shorten >=-##1,->},
extended line/.default=0.09cm]
\begin{axis}[axis background/.style={fill=gray!10},
axis line style={->},
x label style={at={(axis description cs:0.5,-0.1)},very thick,anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=-90,thick,anchor=south},clip=false,xmin=0,xmax=10,ymin=1,ymax=8,axis lines=left,scatter/classes={
a={color=blue},b={color=red}},
xlabel=$x$,
ylabel=$y$]
%scatter
\addplot+[
only marks,scatter src =explicit symbolic,
scatter,mark size=2.9pt]
coordinates{(3.67,1.47)  [b]
(6,2.5) [b]
(6.2,3) [b]
(5,2.55) [b]
(4.89,3.22) [b]
(2.8,1.5)  [b]
(2,2.071)     [b]%
(4,2)     [b]
(3.5,2.5)   [b]
(3,2)   [b]
(4.1,4.8)     [a]
(4.4,2.3)   [b]
(2.23,5.001) [a]
(2.7,4.25)  [a]
(1.5,3.35)   [a]
(1.77,3.47)   [a]
(5,4.74)     [a] %
(3.45,5)     [a]
(2,4.2)   [a]
(2.6,5.3)   [a]
(2.4,4.6)  [a]
(3.24,4.47)  [a]};
%hyperplanes
\addplot[color=red, domain=0:7.5,left]{2/5*x + 2};
\addplot[color=red, domain=7.5:7.9,left]{2/5*x + 2};
\addplot[color=red, domain=9.44:10,left]{2/5*x + 2}
node[sloped,pos=0.2](){$h(x)=0$};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 1.26}
node[sloped,below,pos=0.918](){$h(x)=-1$};
\addplot[color=black,dashed, domain=0:10,left]{2/5*x + 2.74}
node[sloped,above,pos=0.85](){$h(x)=+1$};
%vector w
\node (A) at (2,2/5*2+2) {};
\node  (B) at (5,2/5*5+2) {};
\node (P) at (3.6,4.004) {};
\draw [extended line] ($(A)!(P)!(B)$) -- (P)
node[sloped,above,pos=0.6](){$w$};
%marge
\node (X) at (6,2/5*6+2.74) {};
\node  (Y) at (9,2/5*9+2.74) {};
\node (T) at (6,2/5*6+1.26) {};
\node  (Z) at (9,2/5*9+1.26) {};
\node (M) at (7.5,2/5*7.5+2) {};
\draw [marge] ($(X)!(M)!(Y)$) -- (M);
\draw [marge] ($(T)!(M)!(Z)$) -- (M);
%support vectors
\node (svm) at (3.5,7) {Vecteurs de support};
\node (s1) at (5,4.74) {};
\node (s2) at  (2,2.071) {};
\draw [->] (svm)--(s1);
\draw [->] (svm)--(s2);
\end{axis}
\end{tikzpicture}
%\caption{Hyperplan optimale}
\end{figure}}


\end{frame}


\end{document}

答案2

  • tikzpicture选项移至文档序言。
  • 框架的内容无法放在一个框架中,因此在下面的 MWE 中将其分为两个框架:
  • 我擅自对机器人图做了一些小改动
\documentclass{beamer}
\usetheme{Warsaw}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta,
                calc,
                positioning}
\tikzset{
  arr/.style = {-{Straight Barb[scale=0.8]},semithick},
marge/.style = {arr, densely dashed},
        }


\begin{document}
\begin{frame}[t]
\frametitle{La théorie des SVM}% \vspace{10pt}

\only<1-3>{
\begin{block}{L'hyperplan optimale}
L'hyperplan qui posséde une \alert{marge} maximale.
\end{block}}
\only<2-3>{
\begin{block}{La marge}
Deux fois la \alert{distance minimale} entre l'hyperplan et les observations.
\end{block}}
\only<3>{
    \begin{figure}
    \centering
\begin{tikzpicture}[scale=0.6]
\begin{axis}[
    axis lines=left,
    axis line style={-{Straight Barb[scale=0.8]}},
    axis background/.style={fill=gray!10},
    xmin=0, xmax=10,
    ymin=1, ymax=8,
    scatter/classes={a={color=blue},b={color=red}},
    xlabel=$x$,
    ylabel=$y$,
    ticklabel style={font=\footnotesize}
            ]
%scatter
\addplot+[only marks,
          scatter src =explicit symbolic,
          scatter,
          mark size=2.9pt] coordinates {
            (3.67,1.47) [b]
            (6,2.5)     [b]
            (6.2,3)     [b]
            (5,2.55)    [b]
            (4.89,3.22) [b]
            (2.8,1.5)   [b]
            (2,2.071)   [b]
            (4,2)       [b]
            (3.5,2.5)   [b]
            (3,2)       [b]
            (4.1,4.8)   [a]
            (4.4,2.3)   [b]
            %
            (2.23,5)    [a]
            (2.7,4.25)  [a]
            (1.5,3.35)  [a]
            (1.77,3.47) [a]
            (5,4.74)    [a] %
            (3.45,5)    [a]
            (2,4.2)     [a]
            (2.6,5.3)   [a]
            (2.4,4.6)   [a]
            (3.24,4.47) [a]};
% hyperplanes
\path (0,2) -- node (h) [pos=0.8, inner sep=2pt, sloped] {$h(x)=0$} (10,6);
\draw[red] (0,2) -- (h.west) (h.east) -- (10,6);
%
\draw[dashed] (0,1.25) -- (10,5.25) (0,2.75) -- (10,6.75);
% marge
\coordinate (M) at ($(h.center)!0.72!+90:(h.east)$);
\coordinate (N) at ($(h.center)!0.72!-90:(h.east)$);
\draw[marge] (h.north) -- (M);
\draw[marge] (h.south) -- (N);
\end{axis}
    \end{tikzpicture}
%\caption{Hyperplan optimale}
\end{figure}
    }
\end{frame}

\begin{frame}[t]
\frametitle{La théorie des SVM}
\only<1->{
\begin{block}{Normalisation}
Pour les observations à limite de la marge on pose: 

$\arrowvert w\cdot x_{marge}+w_0\arrowvert=1$, avec:
$\begin{cases}
 w{\cdot} x_{marge+}+w_0=+1 \\
 w{\cdot} x_{marge-}+w_0=-1
\end{cases}$
\end{block}}

\only<2->{
    \begin{figure}
    \centering
\begin{tikzpicture}[scale=0.6]
\begin{axis}[
    axis lines=left,
    axis line style={-{Straight Barb[scale=0.8]}},
    axis background/.style={fill=gray!10},
    xmin=0, xmax=10,
    ymin=1, ymax=8,
    scatter/classes={a={color=blue},b={color=red}},
    xlabel=$x$,
    ylabel=$y$,
    ticklabel style={font=\footnotesize}
            ]
%scatter
\addplot+[only marks,
          scatter src =explicit symbolic,
          scatter,
          mark size=2.9pt] coordinates {
            (3.67,1.47) [b]
            (6,2.5)     [b]
            (6.2,3)     [b]
            (5,2.55)    [b]
            (4.89,3.22) [b]
            (2.8,1.5)   [b]
            (2,2.071)   [b]
            (4,2)       [b]
            (3.5,2.5)   [b]
            (3,2)       [b]
            (4.1,4.8)   [a]
            (4.4,2.3)   [b]
            %
            (2.23,5)    [a]
            (2.7,4.25)  [a]
            (1.5,3.35)  [a]
            (1.77,3.47) [a]
            (5,4.74)    [a] %
            (3.45,5)    [a]
            (2,4.2)     [a]
            (2.6,5.3)   [a]
            (2.4,4.6)   [a]
            (3.24,4.47) [a]};
% hyperplanes
\path (0,2.75) -- node (h) [pos=0.78, above, sloped] {$h(x)=+1$} (10,6.75);
\path (0,1.25) -- node (h) [pos=0.84, below, sloped] {$h(x)=-1$} (10,5.25);
\path (0,2) --  coordinate[pos=0.4] (A) 
                node (h) [pos=0.8, inner sep=2pt, sloped] {$h(x)=0$} (10,6);
\draw[red] (0,2) -- (h.west) (h.east) -- (10,6);
%
\draw[dashed] (0,1.25) -- (10,5.25) (0,2.75) -- (10,6.75);
% marge
\coordinate (M) at ($(h.center)!0.72!+90:(h.east)$);
\coordinate (N) at ($(h.center)!0.72!-90:(h.east)$);
\draw[marge] (h.north) -- (M);
\draw[marge] (h.south) -- (N);
%vector w
\draw [arr] (A) -- node[sloped,above] {$w$} ($(A)!0.1!90:(h.east)$);
%support vectors
\node (svm) at (4,7) {Vecteurs de support};
\node (s1) at (5,4.74) {};
\node (s2) at (2,2.07) {};
\draw [arr] (svm)--(s1);
\draw [arr] (svm)--(s2);
\end{axis}
    \end{tikzpicture}
%\caption{Hyperplan optimale}
\end{figure}
    }
\end{frame}

\end{document}

最后一张幻灯片是:

在此处输入图片描述

相关内容