# Matrices as labels in xymatrix

How can I use a matrix as label in the xymatrix environment? I tried to nest matrices (naively) but it seems to be rather complicated.

\xymatrix{
A \ar[r]^{\xymatrix{f \\ g}} & B
}

-

No, you can't; but you can use \substack, provided by amsmath:

\documentclass{article}
\usepackage[all,cmtip]{xy}
\usepackage{amsmath}
\begin{document}
\xymatrix{
A \ar[r]^{\substack{f \\ g}} & B
}
\end{document}


An alternative is the smallmatrix environment:

\documentclass{article}
\usepackage[all,cmtip]{xy}
\usepackage{amsmath}
\begin{document}
\xymatrix{
A \ar[r]^{\left[\begin{smallmatrix}a&b\\c&d\end{smallmatrix}\right]} & B
}
\end{document}


-
Beautiful, thanks! – user15412 Jul 13 '12 at 17:02
@user15412 Another possibility is to say \ar[r]^{f}_{g} – egreg Jul 13 '12 at 17:04
What if I want to insert a square matrix? – user15412 Jul 13 '12 at 17:13
@user15412 I've added a way – egreg Jul 13 '12 at 17:20