1

I'm trying to use tikz in beamer as follows but get an error "Undefined control sequence. \end{frame}"

My MWE is:

\documentclass{beamer}
\setbeamercovered{highly dynamic}
%\setbeamertemplate{bibliography item}{}

\usepackage{lipsum, ragged2e, etoolbox}
\usepackage{lmodern}
\usepackage{graphicx}      % include this line if your document contains figures
%\usepackage{natbib}        % required for bibliography
\usepackage{booktabs} % For formal tables
\usepackage{dsfont, color, soul, tikz, amsmath, amssymb, amsfonts, amsthm, graphicx, arydshln, fixmath, mathtools, multirow, boldline, xcolor, colortbl, url, algorithm, algpseudocode, subfig, media9, hyperref, blindtext, import, tcolorbox}
\usepackage{caption}
\captionsetup[figure]{labelformat=empty}
\usetikzlibrary{arrows, fit, matrix, positioning, shapes, backgrounds}

\addtobeamertemplate{footnote}{}{\vspace{2ex}}
\makeatletter
\def\hrulefill{\leavevmode\leaders\hrule height 2pt\hfill\kern\z@}
\makeatother

\newcommand\blfootnote[1]{%
    \begingroup
    \renewcommand\thefootnote{}\footnote{#1}%
    \addtocounter{footnote}{-1}%
    \endgroup
}
    
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\usetheme{Madrid}

\setbeamercolor{section in head/foot}{parent=palette quaternary}

\makeatletter
\setbeamertemplate{footline}
{%
    \vskip-9ex%
%   \begin{beamercolorbox}{}
%       \hfill\usebeamercolor[fg]{navigation symbols dimmed}%
%       \insertslidenavigationsymbol
%       \insertframenavigationsymbol
%       \insertsubsectionnavigationsymbol
%       \insertsectionnavigationsymbol
%       \insertdocnavigationsymbol
%       \insertbackfindforwardnavigationsymbol
%   \end{beamercolorbox}%    
%   \begin{beamercolorbox}[ht=3ex,dp=4ex]{section in head/foot}%
%       \insertnavigation{.9\paperwidth}
%   \end{beamercolorbox}%
\leavevmode%
\hbox{%
    \begin{beamercolorbox}[wd=0.9\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
        \insertnavigation{.9\paperwidth}
%       \usebeamerfont{author in head/foot}{}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=0\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
        \usebeamerfont{title in head/foot}{}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.25ex,dp=1ex,center]{date in head/foot}%
        \insertframenumber{} / \inserttotalframenumber\hspace*{1ex}
\end{beamercolorbox}}%
\vskip0pt%
}%
\makeatother

%\AtBeginSection[]{
%   \begin{frame}
%   \vfill
%   \centering
%   \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
%       \usebeamerfont{title}\insertsectionhead\par%
%   \end{beamercolorbox}
%   \vfill
%\end{frame}
%}

%\makeatother
%\setbeamertemplate{footline}
%{
%   \leavevmode%
%   \hbox{%
%       \begin{beamercolorbox}[wd=0.9\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
%           \usebeamerfont{author in head/foot}{}
%       \end{beamercolorbox}%
%       \begin{beamercolorbox}[wd=0\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
%           \usebeamerfont{title in head/foot}{}
%       \end{beamercolorbox}%
%       \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.25ex,dp=1ex,center]{date in head/foot}%
%           \insertframenumber{} / \inserttotalframenumber\hspace*{1ex}
%   \end{beamercolorbox}}%
%   \vskip0pt%
%}
%\makeatletter

\title{My title}

% A subtitle is optional and this may be deleted
%\subtitle{Optional Subtitle}

\author{Me}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[University] % (optional, but mostly needed)
{
  %\inst{1}%
  Electrical and Computer Engineering Department\\
  \vspace{.3cm}
  }


\date{October 1, 2019}

\begin{document}

\begin{frame}
  \begin{equation}
\lambda_{\max}(W_c) = \begin{bmatrix}
\begin{tikzpicture}
\matrix (m) [
matrix of math nodes,
nodes in empty cells,
minimum width=width("998888"),
] {
    1.5678 & 9.1645 & 5.2552 & 3.6413\\
    4.3001 & 1.5605 & 5.2552 & 3.6413\\
    6.0162 & 4.0937 & 1.5561 & 3.6413\\
    10.0278 & 5.6221 & 3.8836 & 1.5504\\
};
\draw (m-2-1.south west) rectangle (m-2-4.north east);
\draw (m-1-3.north west) rectangle (m-4-3.south east);
\scoped[on background layer]
{
    \node[fill=gray!30, fit=(m-2-3)(m-2-3) ]   {};
}
\end{tikzpicture}
\end{bmatrix}
\end{equation}
\end{frame}

\end{document} 
7
  • Use \matrix [ampersand replacement=\&,...] and replace all & by \&. Sep 1, 2020 at 2:47
  • @HenriMenke Thanks. Also how can I resize it? Using \scalebox{0.75}{\begin{minipage}{\linewidth} \end{minipage}} around it produces error.
    – Mohammad
    Sep 1, 2020 at 2:59
  • You have to put that inside the frame environment. Sep 1, 2020 at 3:10
  • It is already in the frame environment!
    – Mohammad
    Sep 1, 2020 at 3:13
  • I see, then you just have to put it in the right place. Try putting it around equation. Sep 1, 2020 at 3:14

1 Answer 1

3

You need to add fragile to your frames with tikzpictures:

\documentclass{beamer}
\setbeamercovered{highly dynamic}
%\setbeamertemplate{bibliography item}{}

\usepackage{lipsum, ragged2e, etoolbox}
\usepackage{lmodern}
\usepackage{graphicx}      % include this line if your document contains figures
%\usepackage{natbib}        % required for bibliography
\usepackage{booktabs} % For formal tables
\usepackage{dsfont, color, soul, tikz, amsmath, amssymb, amsfonts, amsthm, graphicx, arydshln, fixmath, mathtools, multirow, boldline, xcolor, colortbl, url, algorithm, algpseudocode, subfig, media9, hyperref, blindtext, import, tcolorbox}
\usepackage{caption}
\captionsetup[figure]{labelformat=empty}
\usetikzlibrary{arrows, fit, matrix, positioning, shapes, backgrounds}

\addtobeamertemplate{footnote}{}{\vspace{2ex}}
\makeatletter
\def\hrulefill{\leavevmode\leaders\hrule height 2pt\hfill\kern\z@}
\makeatother

\newcommand\blfootnote[1]{%
    \begingroup
    \renewcommand\thefootnote{}\footnote{#1}%
    \addtocounter{footnote}{-1}%
    \endgroup
}
    
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\usetheme{Madrid}

\setbeamercolor{section in head/foot}{parent=palette quaternary}

\makeatletter
\setbeamertemplate{footline}
{%
    \vskip-9ex%
%   \begin{beamercolorbox}{}
%       \hfill\usebeamercolor[fg]{navigation symbols dimmed}%
%       \insertslidenavigationsymbol
%       \insertframenavigationsymbol
%       \insertsubsectionnavigationsymbol
%       \insertsectionnavigationsymbol
%       \insertdocnavigationsymbol
%       \insertbackfindforwardnavigationsymbol
%   \end{beamercolorbox}%    
%   \begin{beamercolorbox}[ht=3ex,dp=4ex]{section in head/foot}%
%       \insertnavigation{.9\paperwidth}
%   \end{beamercolorbox}%
\leavevmode%
\hbox{%
    \begin{beamercolorbox}[wd=0.9\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
        \insertnavigation{.9\paperwidth}
%       \usebeamerfont{author in head/foot}{}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=0\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
        \usebeamerfont{title in head/foot}{}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.25ex,dp=1ex,center]{date in head/foot}%
        \insertframenumber{} / \inserttotalframenumber\hspace*{1ex}
\end{beamercolorbox}}%
\vskip0pt%
}%
\makeatother

%\AtBeginSection[]{
%   \begin{frame}
%   \vfill
%   \centering
%   \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
%       \usebeamerfont{title}\insertsectionhead\par%
%   \end{beamercolorbox}
%   \vfill
%\end{frame}
%}

%\makeatother
%\setbeamertemplate{footline}
%{
%   \leavevmode%
%   \hbox{%
%       \begin{beamercolorbox}[wd=0.9\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
%           \usebeamerfont{author in head/foot}{}
%       \end{beamercolorbox}%
%       \begin{beamercolorbox}[wd=0\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
%           \usebeamerfont{title in head/foot}{}
%       \end{beamercolorbox}%
%       \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.25ex,dp=1ex,center]{date in head/foot}%
%           \insertframenumber{} / \inserttotalframenumber\hspace*{1ex}
%   \end{beamercolorbox}}%
%   \vskip0pt%
%}
%\makeatletter

\title{My title}

% A subtitle is optional and this may be deleted
%\subtitle{Optional Subtitle}

\author{Me}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[University] % (optional, but mostly needed)
{
  %\inst{1}%
  Electrical and Computer Engineering Department\\
  \vspace{.3cm}
  }


\date{October 1, 2019}

\begin{document}

\begin{frame}[fragile] %<--- Add fragile here
  \begin{equation}
\lambda_{\max}(W_c) = \begin{bmatrix}
\begin{tikzpicture}
\matrix (m) [
matrix of math nodes,
nodes in empty cells,
minimum width=width("998888"),
] {
    1.5678 & 9.1645 & 5.2552 & 3.6413\\
    4.3001 & 1.5605 & 5.2552 & 3.6413\\
    6.0162 & 4.0937 & 1.5561 & 3.6413\\
    10.0278 & 5.6221 & 3.8836 & 1.5504\\
};
\draw (m-2-1.south west) rectangle (m-2-4.north east);
\draw (m-1-3.north west) rectangle (m-4-3.south east);
\scoped[on background layer]
{
    \node[fill=gray!30, fit=(m-2-3)(m-2-3) ]   {};
}
\end{tikzpicture}
\end{bmatrix}
\end{equation}
\end{frame}

\end{document}

Here is the output: enter image description here

0

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.