0

I am trying to use a tikz figure in a beamer template but unfortunately I keep having an error saying :

LaTex Error : Environment axis undefined

This is the code used to plot the template :

% !TEX encoding = UTF-8 Unicode
\documentclass[french]{beamer}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}

%\usepackage[T1]{fontenc}
\UseRawInputEncoding


\usepackage{pgfpages}
\usepackage{pgf, tikz, adjustbox}

\usetikzlibrary{arrows.meta,
                patterns.meta
                }

% other packages
\usepackage{latexsym,amsmath,xcolor,multicol,booktabs,calligra}
\usepackage{graphicx,listings,stackengine}

%% Enable only in Xelatex
% \usepackage{pstricks}

\author{XXX}
\title{Etalement à interface élastique}
\subtitle{Presentation}
\institute [Sorbonne Université - ESPCI, Paris] {Laboratoire \\PSL University}
\date{\today}

\usepackage{YTU}

% defs
\def\cmd#1{\texttt{\color{red}\footnotesize $\backslash$#1}}
\def\env#1{\texttt{\color{blue}\footnotesize #1}}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\definecolor{halfgray}{gray}{0.55}

\lstset{
    basicstyle=\ttfamily\small,
    keywordstyle=\bfseries\color{deepblue},
    emphstyle=\ttfamily\color{deepred},    % Custom highlighting style
    stringstyle=\color{deepgreen},
    numbers=left,
    numberstyle=\small\color{halfgray},
    rulesepcolor=\color{red!20!green!20!blue!20},
    frame=shadowbox,
}


\begin{document}

\begin{frame}
    \titlepage

    
    \begin{note}
        {Introduce your self}
    \end{note}

\end{frame}


% THIS IS THE FRAME OF CONCERN

\begin{frame}[fragile]

\begin{figure}[h]   
\centering
\begin{tikzpicture}[dot/.style = {circle, fill, inner sep=1.0pt, node contents={}}]

\begin{axis}[
  no markers, domain=0:14, samples=200,
  axis lines=none, %axis lines*=left, 
  xlabel=$x$, ylabel=$y$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=5cm, width=17cm,
  xtick={\mean,12.5}, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  grid = major
  ]
  

% On crée les 2 courbes gaussiennes en les nommant et en les remplissant
  \addplot [fill=cyan!20, draw=none, domain=0:14] {gaussian(1.5+\std,\mean)} \closedcycle;
  \addplot [name path=haute,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05};
  \addplot [name path=basse,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)};
  \addplot [very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05}--(14,0); % ligne entre fin de la fonction et axe des abscisses
  

 % On remplit la zone entre les 2 courbes
  \addplot fill between[
    of = haute and basse,
    soft clip={domain=0:14},
    every even segment/.style  = {pink,opacity=.2}
  ];

% On crée une ligne artificielle pour fermer le contour à gauche
\draw[very thick, cyan!50!black]  (0,0) -- (0,0.05011524462);

% On crée les indications pour les quantités H(x,t) et R(x,t)
\draw[dashed,red, stealth-stealth, very thick] (8,0) -- node[fill=cyan!20,scale=0.75] {$h(x,t)$} (8,0.189940);
\draw[dashed,red, stealth-stealth, thick] (7,0.025) -- node[fill=cyan!20,scale=0.75] {$R(x,t)$} (12.5,0.025);

% On remplit la zone intermédiaire entre les 2 rectangles gris (SANS CONTOURS)
\path[fill=cyan!20] (6.25,-0.2) -- (6.25,0) -- (7.75,0) -- (7.75,-0.2) -- (6.25,-0.2);

 

% On crée artificiellement 2 contours qui nous intéressent
\draw[black] (6.25,-0.2) -- (6.25,0);
\draw[black] (7.75,-0.2) -- (7.75,0);

% On construit les rectangles de la base à la main
\draw[black, fill=gray!20] (0,-0.075) -- (0,0) -- (6.25,0) -- (6.25,-0.075) -- (0,-0.075);
\draw[black, fill=gray!20] (14,-0.075) -- (14,0) -- (7.75,0) -- (7.75,-0.075) -- (14,-0.075);
\draw[black, pattern = checkerboard] (0,-0.12) -- (0,-0.075) -- (6.25,-0.075) -- (6.25,-0.12) -- (0,-0.12);
\draw[black, pattern = checkerboard] (14,-0.12) -- (14,-0.075) -- (7.75,-0.075) -- (7.75,-0.12) -- (14,-0.12);

% On crée le label sur le flux Q(x,t)
\draw [yshift=-0.6cm, -stealth](7,-0.1) -- node [fill=cyan!20] {$Q(t)$} (7,0);
\node[right] at (5.5,0.1) {$(\rho,\mu)$};

% On crée les flèches pour les zones à labeliser à la main
\draw[black, stealth-, very thick] (9,0.13) -- node[pos = 0.8,below right,scale=1] {Elastic membrane} (12,0.25);
\draw[black, stealth-, very thick] (6,0.03) -- node[pos = 0.8,below left,scale=1] {Silicon oil} (3,0.25);
\draw[black, -stealth, very thick] (5,-0.2) -- node[pos = 0.2,above left,scale=1] {Checkerboard pattern} (5,-0.12);
%\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$Q(t)$} (axis cs:5.96,0);

% Construction des axes
\draw[dotted,-stealth,thick] (7, 0) -- (15,  0) node[right] {$\underline{e}_x$}; % x-axis
\draw[dotted,-stealth,thick] (7, 0) -- ( 7,0.325) node[above] {$\underline{e}_z$}; % y-axis
\path (7,0) node[black,dot,label=below left:$0$];

\end{axis}

\end{tikzpicture}
\end{figure}

\end{frame}




\end{document}

Since it is an imported template I use an additional file named "YTU.sty" that contains other packages :

\mode<presentation>

\newif\ifbeamer@secheader
\beamer@secheaderfalse

%\DeclareOptionBeamer{secheader}{\beamer@secheadertrue}
\ProcessOptionsBeamer

\useoutertheme[footline=authorinstitutetitle,subsection=false]{smoothbars}
\makeatletter % [add curpage/total page at the bottom](http://tex.stackexchange.com/questions/100838/beamer-dresden-theme-miniframes-appeareance-and-frame-number-insertion)
\newcommand{\frameofframes}{/}
\newcommand{\setframeofframes}[1]{\renewcommand{\frameofframes}{#1}}
\setbeamertemplate{footline} 
  {%
    \begin{beamercolorbox}[colsep=1.5pt]{upper separation line foot}
    \end{beamercolorbox}
    \begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{author in head/foot}%
      \leavevmode{\usebeamerfont{author in head/foot}\insertshortauthor}%
      \hfill%
      {\usebeamerfont{institute in head/foot}\usebeamercolor[fg]{institute in head/foot}\insertshortinstitute}%
    \end{beamercolorbox}%
    \begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
      {\usebeamerfont{title in head/foot}\insertshorttitle}%
      \hfill%
      {\usebeamerfont{frame number}\usebeamercolor[fg]{frame number}\insertframenumber~\frameofframes~\inserttotalframenumber}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[colsep=1.5pt]{lower separation line foot}
    \end{beamercolorbox}
  }
\makeatother

\useinnertheme{circles}

%\useoutertheme{default}
%\useinnertheme[shadow=true]{rounded}

%define qut theme color 
\xdefinecolor{qut}{HTML}{00407a}  %PANTONE 541 BLUE
\setbeamercolor{footline}{bg=qut}
\setbeamercolor{frametitle}{bg=qut,fg=white}
\setbeamercolor{title}{bg=qut}
\setbeamerfont{frametitle}{size=\large}
%\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{bibliography item}[text]
\setbeamertemplate{caption}[numbered]

\setbeamercolor{palette primary}{use=structure,fg=white,bg=structure.fg}
\setbeamercolor{palette secondary}{use=structure,fg=white,bg=structure.fg!75!black}
\setbeamercolor{palette tertiary}{use=structure,fg=white,bg=structure.fg!50!black}
\setbeamercolor{palette quaternary}{fg=white,bg=structure.fg!50!black}
%\setbeamercolor*{sidebar}{use=structure,bg=structure.fg}
\setbeamercolor{titlelike}{parent=palette primary}

%% try
\setbeamercolor{block title}{bg=qut}
\setbeamercolor*{block title example}{use={normal text,example text},bg=white,fg=qut}
\setbeamercolor{fine separation line}{}
\setbeamercolor{item projected}{fg=white}
\setbeamercolor{palette sidebar primary}{use=normal text,fg=normal text.fg}
\setbeamercolor{palette sidebar quaternary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar secondary}{use=structure,fg=structure.fg}
\setbeamercolor{palette sidebar tertiary}{use=normal text,fg=normal text.fg}
%\setbeamercolor{palette sidebar quaternary}{fg=white}
\setbeamercolor{section in sidebar}{fg=brown}
\setbeamercolor{section in sidebar shaded}{fg=grey}
\setbeamercolor{separation line}{}
\setbeamercolor{sidebar}{bg=qut}
\setbeamercolor{sidebar}{parent=palette primary}
\setbeamercolor{structure}{fg=qut}
\setbeamercolor{subsection in sidebar}{fg=brown}
\setbeamercolor{subsection in sidebar shaded}{fg=grey}
\AtBeginSection[]{
    \begin{frame}
        \tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded/hide,subsubsectionstyle=show/shaded/hide]
    \end{frame}
}
\AtBeginSubsection[]{
    \begin{frame}
        \tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded/hide,subsubsectionstyle=show/shaded/hide]
    \end{frame}
}

\mode
<all>

Does anyone can help me to solve this issue please (I am a beginner in beamer) ?

Thanks in advance for your help,

5
  • 1
    pgfplots package is missing Sep 12 at 10:06
  • and macros like \mean and \std are undefined as well as the function gaussian. Go back to whereever you have the code from and copy these bits as well Sep 12 at 10:09
  • Thanks this was a problem with pgflots. But now I have an other issue (I will ask it in a different post)
    – Wiss
    Sep 12 at 10:26
  • @samcarter_is_at_topanswers.xyz Yes, I know it : I have drawn my own figure in a classical latex document but now I am trying beamer for the first time (not my template) so I didn't import everything in order to understand the error. Thank you
    – Wiss
    Sep 12 at 10:28
  • If you are just starting with beamer, you should clean up your preamble now. Don't get into the habit of loading unnecessary packages. Sep 12 at 10:32

1 Answer 1

0

Several problems:

  • you are missing the pgfplots package as well as half a dozen libraries libraries necessary to compile your code. I suggest you go back to wherever you got this code from and also copy the rest

  • macros \mean and \std are not defined

  • the function gaussian is not defined

  • missing \pgfplotsset{compat=newest}

The following code compiles, but does not necessarily give reasonable output. You will have to adjust the dummy definitions I use for the missing macros and functions to get whatever result you are looking for


% !TEX encoding = UTF-8 Unicode
\documentclass[french]{beamer}
%\usepackage{hyperref}
\usepackage[utf8]{inputenc}

%\usepackage[T1]{fontenc}
%\UseRawInputEncoding


\usepackage{pgfpages}
\usepackage{pgf, tikz, adjustbox}

\usetikzlibrary{arrows.meta,
                patterns.meta
                }

% other packages
\usepackage{latexsym,
%,amsmath,xcolor,multicol,
booktabs,calligra}
\usepackage{
%graphicx,
listings,stackengine}

%% Enable only in Xelatex
% \usepackage{pstricks}

\author{XXX}
\title{Etalement à interface élastique}
\subtitle{Presentation}
\institute [Sorbonne Université - ESPCI, Paris] {Laboratoire \\PSL University}
\date{\today}

%\usepackage{YTU}

% defs
\def\cmd#1{\texttt{\color{red}\footnotesize $\backslash$#1}}
\def\env#1{\texttt{\color{blue}\footnotesize #1}}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\definecolor{halfgray}{gray}{0.55}

\lstset{
    basicstyle=\ttfamily\small,
    keywordstyle=\bfseries\color{deepblue},
    emphstyle=\ttfamily\color{deepred},    % Custom highlighting style
    stringstyle=\color{deepgreen},
    numbers=left,
    numberstyle=\small\color{halfgray},
    rulesepcolor=\color{red!20!green!20!blue!20},
    frame=shadowbox,
}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\newcommand{\mean}{3}
\newcommand{\std}{0.2}

\pgfmathdeclarefunction{gaussian}{2}{%
  \pgfmathparse{1/(#1*sqrt(2*pi))*exp(-((x-#2)^2)/(2*#1^2))}%
}

\usetikzlibrary{intersections}
\usetikzlibrary{fillbetween}
\usetikzlibrary{patterns}
\usetikzlibrary{patterns.meta}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{frame}
    \titlepage

    
    \begin{note}
        {Introduce your self}
    \end{note}

\end{frame}


% THIS IS THE FRAME OF CONCERN

\begin{frame}[fragile]

\begin{figure}
\begin{tikzpicture}[dot/.style = {circle, fill, inner sep=1.0pt, node contents={}}]

\begin{axis}[
  no markers, domain=0:14, samples=200,
  axis lines=none, %axis lines*=left, 
  xlabel=$x$, ylabel=$y$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=5cm, width=17cm,
  xtick={\mean,12.5}, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  grid = major
  ]
  

% On crée les 2 courbes gaussiennes en les nommant et en les remplissant
  \addplot [fill=cyan!20, draw=none, domain=0:14] {gaussian(1.5+\std,\mean)} \closedcycle;
  \addplot [name path=haute,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05};
  \addplot [name path=basse,very thick,cyan!50!black] {gaussian(1.5+\std, \mean)};
  \addplot [very thick,cyan!50!black] {gaussian(1.5+\std, \mean)+0.05}--(14,0); % ligne entre fin de la fonction et axe des abscisses
  

 % On remplit la zone entre les 2 courbes
  \addplot fill between[
    of = haute and basse,
    soft clip={domain=0:14},
    every even segment/.style  = {pink,opacity=.2}
  ];

% On crée une ligne artificielle pour fermer le contour à gauche
\draw[very thick, cyan!50!black]  (0,0) -- (0,0.05011524462);

% On crée les indications pour les quantités H(x,t) et R(x,t)
\draw[dashed,red, stealth-stealth, very thick] (8,0) -- node[fill=cyan!20,scale=0.75] {$h(x,t)$} (8,0.189940);
\draw[dashed,red, stealth-stealth, thick] (7,0.025) -- node[fill=cyan!20,scale=0.75] {$R(x,t)$} (12.5,0.025);

% On remplit la zone intermédiaire entre les 2 rectangles gris (SANS CONTOURS)
\path[fill=cyan!20] (6.25,-0.2) -- (6.25,0) -- (7.75,0) -- (7.75,-0.2) -- (6.25,-0.2);

 

% On crée artificiellement 2 contours qui nous intéressent
\draw[black] (6.25,-0.2) -- (6.25,0);
\draw[black] (7.75,-0.2) -- (7.75,0);

% On construit les rectangles de la base à la main
\draw[black, fill=gray!20] (0,-0.075) -- (0,0) -- (6.25,0) -- (6.25,-0.075) -- (0,-0.075);
\draw[black, fill=gray!20] (14,-0.075) -- (14,0) -- (7.75,0) -- (7.75,-0.075) -- (14,-0.075);
\draw[black, pattern = checkerboard] (0,-0.12) -- (0,-0.075) -- (6.25,-0.075) -- (6.25,-0.12) -- (0,-0.12);
\draw[black, pattern = checkerboard] (14,-0.12) -- (14,-0.075) -- (7.75,-0.075) -- (7.75,-0.12) -- (14,-0.12);

% On crée le label sur le flux Q(x,t)
\draw [yshift=-0.6cm, -stealth](7,-0.1) -- node [fill=cyan!20] {$Q(t)$} (7,0);
\node[right] at (5.5,0.1) {$(\rho,\mu)$};

% On crée les flèches pour les zones à labeliser à la main
\draw[black, stealth-, very thick] (9,0.13) -- node[pos = 0.8,below right,scale=1] {Elastic membrane} (12,0.25);
\draw[black, stealth-, very thick] (6,0.03) -- node[pos = 0.8,below left,scale=1] {Silicon oil} (3,0.25);
\draw[black, -stealth, very thick] (5,-0.2) -- node[pos = 0.2,above left,scale=1] {Checkerboard pattern} (5,-0.12);
%\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$Q(t)$} (axis cs:5.96,0);

% Construction des axes
\draw[dotted,-stealth,thick] (7, 0) -- (15,  0) node[right] {$\underline{e}_x$}; % x-axis
\draw[dotted,-stealth,thick] (7, 0) -- ( 7,0.325) node[above] {$\underline{e}_z$}; % y-axis
\path (7,0) node[black,dot,label=below left:$0$];

\end{axis}

\end{tikzpicture}
\end{figure}

\end{frame}




\end{document}

Other comments:

  • you don't need to load hyperref, beamer does this for you. And even if you had to load it, you should load it as last package, not as the very first.

  • don't use \UseRawInputEncoding

  • no need for amsmath, xcolor or graphicx, beamer load all of them for you

  • don't use multicol, beamer has its own column mechanism

  • beamer does not have a floating mechanism, giving floating specifier such as [h] for the figure environment does not make much sense

  • beamer's figure environment is centred by default, no need for \centering

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.