1

I'm trying to use the tickz package in beamer, but the bug is appearing

Missing \endcsname inserted

The code of the diagram I'm drawing is

\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}

If I try this same code into a normal document (without the beamer) it works normally

  • 1
    Welcome to TeX-SE! You need to use ampersand replacement and to load the matrix library. \matrix (m) [ampersand replacement =\&,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) \\}; and \usetikzlibrary{matrix} in the preamble. – marmot Apr 17 at 18:37
  • To understand why marmot's answer works, you can have a look at the answer to tex.stackexchange.com/questions/208408/… – sztruks Apr 17 at 18:43
1

just ad fragile option to \begin{frame} and in preamble missed library matrix. i also suggest to slightly change your matrix's code by using quotes library for edge labels:

\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}

enter image description here

addendum:

above solution can be write much shorter with use of the tikz-cd package:

\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 is the same as before (since tikz-cd is based on matrix library).

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.