[Tex/LaTex] tikz-cd error: Single ampersand used with wrong catcode

tikz-cd

I'm trying to draw a diamond-shaped commutative diagram using the tikz-cd package. Below is my LaTeX source:

\documentclass{amsart} 

\usepackage{tikz} 
\usepackage{tikz-cd}

\begin{document}

\[\begin{tikzcd} 
& A \arrow{dl}\arrow{dr} &\\
B \arrow{dr} & \arrow{dl} C\\
& D & 
\end{tikzcd}\]

\end{document}

When I compile this using pdflatex, I get the error:

Package pgfbasematrix Error: Single ampersand used with wrong catcode.

I've looked around on this site, in the documentation and online, and I've only seen this error arise before when using Beamer or trying to define a newcommand. Since I'm doing neither, I'm at a loss as to what's going on.

Best Answer

You missed one ampersand on the 2nd line.

Also, as observed by @egreg and the OP, the last & in the 1st and 3rd lines are not necessary, and you should start only the 1st line with {}.

\documentclass{amsart} 

\usepackage{tikz} 
\usepackage{tikz-cd}

\begin{document}
\[
\begin{tikzcd} 
{}& A \arrow{dl}\arrow{dr} & \\
B \arrow{dr} &&  C\arrow{dl} \\
  & D  
\end{tikzcd}
\]
\end{document}

enter image description here

Related Question