I want to create a new command to do a certain diagram using tikz. The code looks like this:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\newcommand{\D}[4]{
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=1.5em,column
sep=1.5em,minimum width=2em]
{
&\\
#2& \\
&\\};
\path[thick]
(m-1-2) edge (m-2-1)
edge (m-2-3)
(m-3-2) edge (m-2-1)
edge (m-2-3);
\end{tikzpicture}
}
\begin{document}
\D{a}{b}{c}{d}
\end{document}
But I get this message:
! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options
l.23 \D{a}{b}{c}{d}
How can I solve it?
&character has special catcode and this will not work. See, for example, questions on this site that tries to wrap tabular/array/align/matrix in a command. – Symbol 1 May 08 '17 at 18:06