# tikz and new environment

I would like to creat a new environment in order to draw the following matrix :

\begin{tikzpicture}[baseline,every right delimiter/.style={xshift=-8pt},every left delimiter/.style={xshift=8pt}]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)](m)
{
a  \\
b \\
};
\end{tikzpicture}


Thus I would like the environment be :

\begin{mymatrix}
a  \\
b \\
\end{mymatrix}


However, I do not succeed in making it. Do you know how to proceed ?

Regards

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Ronny May 21 '14 at 16:42
• Addon: Your example is at least missing \usetikzlibrary{matrix} for the matrix of math nodes to work. – Ronny May 21 '14 at 16:46

You need to grab the environment body as a macro argument so:

\documentclass[a4paper,10pt]{report}

\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{environ}

\NewEnviron{mymatrix}{%
\begin{tikzpicture}[baseline,every right delimiter/.style={xshift=-8pt},every left delimiter/.style={xshift=8pt}]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),
ampersand replacement=\&](m)
{\BODY};\end{tikzpicture}}

\begin{document}

\begin{mymatrix}
a  \\
b \\
\end{mymatrix}

\end{document}

• Also ampersand replacement=\& should be added to the options for \matrix and \& for column separator in the body of the matrix. – egreg May 21 '14 at 17:22
• @egreg happy now? – David Carlisle May 21 '14 at 19:50
• Why do you add ampersand replacement=\& ? – hindi May 26 '14 at 18:05
• @hindi I always do what egreg tells me:-) (you don't need it in this one column case but would if you had more columns) – David Carlisle May 26 '14 at 20:56