Tikz 图片在 beamer 问题中

Tikz 图片在 beamer 问题中

我有以下用于 Tikz 交换图的 Latex 代码,该代码在用 Overleaf 编写的普通 Latex 文档中可以正确呈现。我正尝试在 Overleaf 中创建包含相同 Tikz 图的 Beamer 幻灯片演示文稿。但如果我尝试将图表包含在 beamer 幻灯片中,我会收到有关该幻灯片代码的 \end{frame} 部分(就在 \end{document} 之前)的不受控制的错误。只有当我尝试包含图表时才会发生此问题。我尝试在 TexShop 中编译,但也没有成功。提前感谢您的帮助。Beamer 幻灯片的代码如下:

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{default}      % or try Darmstadt, Madrid, Warsaw, ...
  \usecolortheme{default} % or try albatross, beaver, crane, ...
  \usefonttheme{default}  % or try serif, structurebold, ...
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
} 
\usepackage{amsmath,amssymb,amsfonts,amscd}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage[utf8x]{inputenc}
\usepackage{multicol}
\usepackage{tikz}
\usepackage{parskip}
\usepackage{listings}
\usepackage{multicol}
\usepackage{pgf}
\usetikzlibrary{arrows}
\usetikzlibrary {positioning}
\definecolor {processblue}{cmyk}{0.96,0,0,0}

\begin{document}

\begin{frame}
\usetikzlibrary{matrix}
\begin{center}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em]
  {
     E & E \\
     P & P \\};
  \path[-stealth]
    (m-1-1) edge node [left] {$\pi$} (m-2-1)
            edge node [above] {$\psi$} (m-1-2)
    (m-2-1.east|-m-2-2) edge node [below] {}
            node [above] {$\bar{\psi}$} (m-2-2)
    (m-1-2) edge node [right] {$\pi$} (m-2-2);
\end{tikzpicture}  
\end{center}
\end{frame}

\end{document}

答案1

Afragile框架有助于:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}


\begin{document}

\begin{frame}[fragile]
\begin{center}
    \begin{tikzpicture}
      \matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em]
      {
         E & E \\
         P & P \\};
      \path[-stealth]
        (m-1-1) edge node [left] {$\pi$} (m-2-1)
                edge node [above] {$\psi$} (m-1-2)
        (m-2-1.east|-m-2-2) edge node [below] {}
                node [above] {$\bar{\psi}$} (m-2-2)
        (m-1-2) edge node [right] {$\pi$} (m-2-2);
    \end{tikzpicture}  
\end{center}
\end{frame}

\end{document}

在此处输入图片描述

相关内容