I am getting two errors when seeking to use copy this matrix over to my beamer presentation slides:
Undefined control sequence.
Package pgf Error: Single ampersand used with wrong catcode. (This one occurs twice).
A reproducible version of the faulty code:
\documentclass{beamer}
\graphicspath{{Images/}{./}}
\usepackage{amssymb, amsmath,tikz-cd}
\usepackage{booktabs}
\usetheme{Madrid}
\usefonttheme{default}
\usepackage{palatino}
\usepackage[default]{opensans}
\usepackage{amssymb, amsmath, tikz-cd}
\useinnertheme{circles}
\begin{document}
\begin{frame}{Needleman-Wunsch Algorithm}
$\begin{pmatrix}
\begin{tikzcd}[cramped, row sep = 8, column sep = 4]
0\arrow[r]\arrow[dr]\arrow[d] & 2\arrow[r] & 3\arrow[r] & 4\arrow[r]\arrow[dr] & 9 \
5\arrow[d] & 1\arrow[r]\arrow[dr]\arrow[d] & 2\arrow[r]\arrow[dr]\arrow[d] & 3\arrow[dr]\arrow[d] & 7 \
8\arrow[d] & 4\arrow[r]\arrow[dr]\arrow[d] & 5\arrow[r]\arrow[dr] & 6 & 8\arrow[d] \
15\arrow[d] & 11\arrow[d] & 7\arrow[d] & 6\arrow[dr]\arrow[d] & 10 \
18 & 14 & 10 & 9 & 11 \
\end{tikzcd}
\end{pmatrix}$
\end{frame}
\end{document}
This is not rendering the matrix properly. It is not showing the even columns:
I first successfully created the diagram in a separate project which is coded as follows:
\documentclass{beamer}
\usepackage{amssymb, amsmath,tikz-cd}
\begin{document}
$\begin{pmatrix}
\begin{tikzcd}[cramped, row sep = 8, column sep = 4]
0\arrow[r]\arrow[dr]\arrow[d] & 2\arrow[r] & 3\arrow[r] & 4\arrow[r]\arrow[dr] & 9 \
5\arrow[d] & 1\arrow[r]\arrow[dr]\arrow[d] & 2\arrow[r]\arrow[dr]\arrow[d] & 3\arrow[dr]\arrow[d] & 7 \
8\arrow[d] & 4\arrow[r]\arrow[dr]\arrow[d] & 5\arrow[r]\arrow[dr] & 6 & 8\arrow[d] \
15\arrow[d] & 11\arrow[d] & 7\arrow[d] & 6\arrow[dr]\arrow[d] & 10 \
18 & 14 & 10 & 9 & 11 \
\end{tikzcd}
\end{pmatrix}$
\end{document}
This correctly rendered the output:
Why the image is not rendering properly in my presentation slides, when I have simply copied the code over? Is there a way to get the desired outcome?



fragileframe option, but with the missing line breaks and comments in the preamble it is hard to tell... – samcarter_is_at_topanswers.xyz Feb 01 '23 at 17:18fragileframe option – samcarter_is_at_topanswers.xyz Feb 01 '23 at 17:35