1

I am making a beamer presentation that has some tikzpictures and pgfplots and I get this error : >Illegal parameter number in definition of \beamer@doifinframe. I tried adding fragile in \begin{frame} but the error still shows up, the pdf is still generated but when the presentation gets bigger(more tikzpictures and pgfplots} the output stops.

%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
    here iit is probably better to use \begin{onlyenv}<...> ... \end{onlyenv} instead of \only<...>}{...}, at least for me the example compiles using onlyenv
    – daleif
    Jun 23, 2022 at 8:27

2 Answers 2

4

You can fix the error by using ##1 instead of #1 in your custom style (you need to double the # because you are using it inside another macro):

\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}
0
  • Move tikzpicture option to document preamble.
  • Content of your frame cannot be fit on on one frame, so in MWE below are split between two frames:
  • I took liberty and make small changes in bot diagrams
\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}

Last slide is:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .