2

Is it possible to use "\newcommand" with a TikZ-matrix ?

This code doesn't work...

\documentclass{minimal}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}


\newcommand \toto{%
\begin{tikzpicture}
\matrix [matrix of math nodes]
{
2 & 2 & 2 & 2 & 4 & 2 & 4 & 2 \\
};
\end{tikzpicture}
}


\toto

\end{document}

Thanks.

1
  • 5
    Please, don't use minimal for examples. It's not meant for this purpose.
    – egreg
    Dec 11, 2023 at 14:43

1 Answer 1

4

It works if you replace the &, e.g.:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}


\newcommand{\toto}{%
\begin{tikzpicture}
\matrix [matrix of math nodes,ampersand replacement=\&]
{
2 \& 2 \& 2 \& 2 \& 4 \& 2 \& 4 \& 2 \\
};
\end{tikzpicture}
}


\toto

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .