Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
Ah, thanks. I toyed with changing the number of ampersands to see if that was the problem, but missed using {}. Why is this not always necessary when beginning a line with &? –  Alex Becker May 31 '13 at 22:30
    
@AlexBecker, I don't why but sometimes we have to insert some characters with no effect, like {} to change the behavior of others. Maybe some expert could explain better. –  Sigur May 31 '13 at 22:32
    
It's necessary only to start the first line with {}; the trailing & are not needed. I don't really know why the first & must be preceded by something (even empty), but it surely has to do with TikZ internals (matrices are quite strange in how they use &). –  egreg May 31 '13 at 22:42
    
@egreg, I'll edit the post and cite your note. –  Sigur May 31 '13 at 22:45
1  
@Sigur I believe that the trailing & is not needed on the first line either. I just throw them in for bookkeeping. –  Alex Becker May 31 '13 at 22:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.