![在创建矩阵时,beamer 中的“tikzpicture”出现问题](https://linux22.com/image/420099/%E5%9C%A8%E5%88%9B%E5%BB%BA%E7%9F%A9%E9%98%B5%E6%97%B6%EF%BC%8Cbeamer%20%E4%B8%AD%E7%9A%84%E2%80%9Ctikzpicture%E2%80%9D%E5%87%BA%E7%8E%B0%E9%97%AE%E9%A2%98.png)
我试图在 beamer 中使用 tikz,如下所示,但出现错误“未定义的控制序列。\end{frame}”
我的 MWE 是:
\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}
答案1
您需要使用 s 添加fragile
到您的框架中tikzpicture
:
\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}