TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’m using tikz-cd for diagrams, and have a medium-sized diagram that I want to re-use several times. However, when I try using a definition like:

\newcommand{\myarrow}{$\begin{tikzcd} A \ar{r} & B \end{tikzcd}$

I get an error:

ERROR: Package pgfbasematrix Error: Single ampersand used with wrong catcode.

Is it possible to put a tikz-cd diagram into a defined command somehow?

share|improve this question
up vote 15 down vote accepted

It's a known problem with TikZ matrices:

  $\begin{tikzcd}[ampersand replacement=\&] A \ar{r} \& B \end{tikzcd}$}

The problem is that tikzpicture wants to do some juggling with the meaning of &, but it's impossible if the & has been found as the replacement text of a macro, as in your original definition. Happily, it provides the

ampersand replacement=...

key that allows to define some command as substitute for &, avoiding the need to do the jugglings.

share|improve this answer

Your Answer


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.