1

Possible Duplicate:
Problem with defining shortcuts for TikZ matrices.

I tried to use a tikz Matrix in a LaTeX document as the following:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \matrix{
    \node{a}; & \node{b}; \\
    \node{c}; & \node{d}; \\
    };
\end{tikzpicture}
\end{document}

Everything is ok. But when I tried to use it in a LaTeX command as the following:

\documentclass{article}
\usepackage{tikz}

\newcommand{\Foo}{
\begin{tikzpicture}
    \matrix{
    \node{a}; & \node{b}; \\
    \node{c}; & \node{d}; \\
    };
\end{tikzpicture}
}

\begin{document}
\Foo
\end{document}

It will report the following error:

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

Does anyone know how to solve this? thanks.

marked as duplicate by Loop Space, Seamus, Martin Scharrer Aug 9 '11 at 12:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    See Problem with defining shortcuts for TikZ matrices. which seems to be a duplicate. – Martin Scharrer Aug 9 '11 at 11:42
  • 1
    I agree with Martin. This is a subtle issue with TikZ matrices and is tricky to figure out. The question that Martin links to gives a way to solve it. If that doesn't work for you, edit this question to explain why not; otherwise we'll close it as a duplicate of that one so that others with this question can more easily find an answer. – Loop Space Aug 9 '11 at 11:45
  • Yes, that solution solved this problem, please close this question, thanks. – ocean Aug 9 '11 at 11:56