# smallmatrix using tikzpicture

I wish to use tikzpicture instead of smallmatrix, because the former offers better control for dots via this post. However, the code

$\Z^4\!\xleftarrow{ \begin{tikzpicture}[baseline=(current bounding box.center)] \matrix (m) [matrix of math nodes,nodes in empty cells,right delimiter={]},left delimiter={[} ]{ & & & & & \\ 1& & -1& & 1& \\ 1& & -1& & 1& \\ & 1& & -1& & 1\\}; \end{tikzpicture} }\!\Z^6$


returns errors (unless tikzpicture is outside of \xleftarrow). How do I get the output of

$\Z^4\!\xleftarrow{ \left[\!\begin{smallmatrix}&&&&&\vspace{6pt}\\ 1&&-\!1&&1&\\1&&-\!1&&1&\\ &1&&-\!1&&1\\\end{smallmatrix}\!\right]}\!\Z^6$


(everything tight and small) using tikzpicture?

You need ampersand replacement to keep & unchanged.

\documentclass[border=7pt]{standalone}
\usepackage{mathtools,amssymb,tikz}
\usetikzlibrary{matrix}
\newcommand*{\Z}{\mathbb{Z}}
\begin{document}
$\Z^4\!\xleftarrow{% \begin{tikzpicture}[baseline=(current bounding box.center)] \matrix (m) [ matrix of math nodes, nodes in empty cells, right delimiter={]}, left delimiter={[}, ampersand replacement=\&, % <-- this is what you need nodes={scale=.5}] { \& \& \& \& \& \\ 1 \& \& -1 \& \& 1 \& \\ 1 \& \& -1 \& \& 1 \& \\ \& 1 \& \& -1 \& \& 1 \\ }; \end{tikzpicture}% }\!\Z^6$
\end{document}


This cries for an ampersand replacement.

\documentclass{article}
\usepackage{mathtools}
\usepackage{bbm}
\newcommand{\Z}{\mathbbm{Z}}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}

$\Z^4\!\xleftarrow{\vcenter{\hbox{ \begin{tikzpicture} \matrix (m) [matrix of math nodes,nodes in empty cells,right delimiter={]}, left delimiter={[},ampersand replacement=\&]{ \& \& \& \& \& \\ 1\& \& -1\& \& 1\& \\ 1\& \& -1\& \& 1\& \\ \& 1\& \& -1\& \& 1\\}; \end{tikzpicture} }}}\!\Z^6$
\end{document}