beamer 中的 Tikzlibrary 包

beamer 中的 Tikzlibrary 包

我正在尝试在 beamer 中使用 tickz 包,但出现了错误

Missing \endcsname inserted

我绘制的图表的代码是

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{utopia}
\usepackage{tikz}
\usetikzlibrary{shadows}
\usetikzlibrary{arrows,shapes}

\usetheme{Madrid}
\usecolortheme{default}

\begin{document}

\begin{frame}
\begin{equation*}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum     width=2em]
{
 K_0(I) & K_0(A) & K_0(B) \\
 K_1(B) & K_1(A) & K_1(I) \\};
\path[-stealth]
(m-2-1) edge node [left] {$\delta_1$} (m-1-1)
(m-1-1) edge node [above] {$K_0(\varphi)$} (m-1-2)
(m-1-2) edge node [above] {$K_0(\psi)$} (m-1-3)
(m-2-3) edge node [below] {$K_1(\varphi)$} (m-2-2)
(m-2-2) edge node [below] {$K_1(\psi)$} (m-2-1);
\end{tikzpicture}
\end{equation*}
\end{frame}
\end{document}

如果我尝试将相同的代码放入普通文档(没有投影仪),它可以正常工作

答案1

只需在序言中将fragile选项添加到错过的库中即可。我还建议通过使用边缘标签库稍微更改矩阵的代码:\begin{frame}matrixquotes

\documentclass{beamer}
\usetheme{Madrid}
\usecolortheme{default}
%\usepackage[utf8]{inputenc}  % it is used by default, as i remember
\usepackage{utopia}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                matrix,
                quotes,
                shapes}

\begin{document}
\begin{frame}[fragile]  % <---
    \begin{center}
\begin{tikzpicture}[auto=left]
\matrix (m) [matrix of math nodes,
             row sep=3em, column sep=5em,
             ]
{
 K_0(I) & K_0(A) & K_0(B) \\
 K_1(B) & K_1(A) & K_1(I) \\
 };
\path[-Stealth]
    (m-2-1) edge["$\delta_1$"]      (m-1-1)
    (m-1-1) edge["$K_0(\varphi)$"]  (m-1-2)
    (m-1-2) edge["$K_0(\psi)$"]     (m-1-3)
    (m-2-3) edge["$K_1(\varphi)$"]  (m-2-2)
    (m-2-2) edge["$K_1(\psi)$"]     (m-2-1);
\end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

在此处输入图片描述

附录:

使用以下tikz-cd包,上述解决方案可以变得更短:

\documentclass{beamer}
\usetheme{Madrid}
\usecolortheme{default}
%\usepackage[utf8]{inputenc}  % it is used by default, as i remember
\usepackage{utopia}
\usepackage{tikz-cd}

\begin{document}
\begin{frame}[fragile]
    \begin{center}
\begin{tikzcd}[row sep=3em, column sep=5em]
 K_0(I) \ar[r,"K_0(\varphi)"]
        & K_0(A) \ar[r,"K_0(\psi)"]
                & K_0(B)                            \\
 K_1(B) \ar[u,"\delta_1"]
        & K_1(A) \ar[l,"K_0(\psi)"]
                & K_1(I) \ar[l,"K_0(\varphi)"]    \\
\end{tikzcd}
    \end{center}
\end{frame}
\end{document}

rezultat 与以前相同(因为tikz-cd它基于matrix库)。

相关内容