1

I have the following code working very well in article class:

\begin{figure}[!htb]
\centering
\begin{tikzpicture}
    \begin{axis}[
        xlabel=km,
        ylabel=km,
        ylabel near ticks,
        width=0.6\textwidth,
        height=0.6\textwidth,
        only marks,nodes near coords={},
        nodes near coords style={
        coordinate,
        name=\pgfplotspointmeta},
        clip marker paths=true,
        point meta=explicit symbolic
        ]
        \addplot[scatter,mark=*,draw=blue,mark options={scale=1, fill=white}] 
        table [
            x=x,
            y=y,
            meta=label] 
            {
                     x      y    label
            -6960.5568  -1250.1     1
            -7802.8464  -991.1904   2
            -7156.128   -420.0336   3
            -6804.9888  150.012     4
            -5902.6944  -526.7088   5
    };
    \end{axis} 
    %\foreach \i in {1,...,5} {
    %        \node[fill=lime,draw=lime,circle,minimum size=1.5pt,scale=0.2,
    %              label={
    %                    [label distance=-3pt]above:{\scalebox{0.2}{\i}}
    %                     },
    %              ] (T) at (\i) {};
    %}
\end{tikzpicture}
\caption{Fluxo de mínimo custo em $t=1$ (modelo 1)}
\end{figure}
%\end{frame}
\end{document}

However, when I convert the same code in beamer class, an error occurs:

\documentclass[12pt,fleqn]{beamer}

\usepackage[utf8]{inputenc} 
\usepackage[english]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{pgfplotstable}
\usetikzlibrary{positioning}
\usepackage{float}
\usetikzlibrary{plotmarks}
\usetikzlibrary{patterns}
\usepackage{mathtools}
\usetikzlibrary{arrows}
\usetikzlibrary{quotes,angles}
\usetikzlibrary{shapes,shadings}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{fit,shapes.geometric}
\usepackage{xfp}
\usetikzlibrary{math}


\begin{document}

\begin{frame}{Frame Title}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}
    \begin{axis}[
        xlabel=km,
        ylabel=km,
        ylabel near ticks,
        width=0.6\textwidth,
        height=0.6\textwidth,
        only marks,nodes near coords={},
        nodes near coords style={
        coordinate,
        name=\pgfplotspointmeta},
        clip marker paths=true,
        point meta=explicit symbolic
        ]
        \addplot[scatter,mark=*,draw=blue,mark options={scale=1, fill=white}] 
        table [
            x=x,
            y=y,
            meta=label] 
            {
                     x      y    label
            -6960.5568  -1250.1     1
            -7802.8464  -991.1904   2
            -7156.128   -420.0336   3
            -6804.9888  150.012     4
            -5902.6944  -526.7088   5
    };
    \end{axis} 
    \foreach \i in {1,...,5} {
            \node[fill=lime,draw=lime,circle,minimum size=1.5pt,scale=0.2,
                  label={
                        [label distance=-3pt]above:{\scalebox{0.2}{\i}}
                         },
                  ] (T) at (\i) {};
    }
\end{tikzpicture}
\caption{Fluxo de mínimo custo em $t=1$ (modelo 1)}
\end{figure}
\end{frame}

\end{document}

Anyone can help me please?

1 Answer 1

2

Use a fragile frame to avoid the error.

Some other comments:

  • you don't need to load all the amsmath etc. packages, beamer automatically loads them for you

  • beamer does not have a floating mechanism. It makes no sense to load the float package or to specify a floating specifier like [!htb].

  • beamer's figure environment will automatically centre the content, no need for \centering

  • you shouldn't use \scalebox for text. If you choose a suitable small font size instead, the letter shapes will be much easier to read for that size.


\documentclass[12pt,fleqn]{beamer}

\usepackage[utf8]{inputenc} 
\usepackage[english]{babel}
%\usepackage{amsmath,amssymb,amsthm}
\usepackage{pgfplotstable}
\usetikzlibrary{positioning}
%\usepackage{float}
\usetikzlibrary{plotmarks}
\usetikzlibrary{patterns}
\usepackage{mathtools}
\usetikzlibrary{arrows}
\usetikzlibrary{quotes,angles}
\usetikzlibrary{shapes,shadings}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{fit,shapes.geometric}
\usepackage{xfp}
\usetikzlibrary{math}


\begin{document}

\begin{frame}[fragile]{Frame Title}
\begin{figure}%[!htb]
%\centering
\begin{tikzpicture}
    \begin{axis}[
        xlabel=km,
        ylabel=km,
        ylabel near ticks,
        width=0.6\textwidth,
        height=0.6\textwidth,
        only marks,nodes near coords={},
        nodes near coords style={
        coordinate,
        name=\pgfplotspointmeta},
        clip marker paths=true,
        point meta=explicit symbolic
        ]
        \addplot[scatter,mark=*,draw=blue,mark options={scale=1, fill=white}] 
        table [
            x=x,
            y=y,
            meta=label] 
            {
                     x      y    label
            -6960.5568  -1250.1     1
            -7802.8464  -991.1904   2
            -7156.128   -420.0336   3
            -6804.9888  150.012     4
            -5902.6944  -526.7088   5
    };
    \end{axis} 
    \foreach \i in {1,...,5} {
            \node[fill=lime,draw=lime,circle,minimum size=1.5pt,scale=0.2,
                  label={
                        [label distance=-3pt]above:{\Tiny \i}
                         },
                  ] (T) at (\i) {};
    }
\end{tikzpicture}
\caption{Fluxo de mínimo custo em $t=1$ (modelo 1)}
\end{figure}
\end{frame}

\end{document}

You must log in to answer this question.

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