# I want to writing the matrix on the arrow from X to Y 3x3 type, from Z to Y 3x2 type ;

How can I program the above diagram? 

$$\begin{tikzcd} k\oplus k^2 \arrow[r] & k\oplus k^2 & 0\oplus k \arrow[l] \end{tikzcd}$$


• Welcome to TeX SX! Could you post a full compilable code, and explain what X, Y and Z are ? Commented Jul 16, 2018 at 17:17
• X: k \ oplus k ^ 2 , Y: k \oplus k^2 , Z: 0 \oplus k
– tuce
Commented Jul 16, 2018 at 17:19
• @tuce Can you put also a figure to undestand what do you want? Commented Jul 16, 2018 at 17:22
• @sebastiano I added the diagram I wanted to do
– tuce
Commented Jul 16, 2018 at 17:28
• @tuce Very good! Thus you have had several answers. Good work. Commented Jul 17, 2018 at 6:51

Here are two realizations; to be honest, I'd prefer the second one. For the first, I define a variant of smallmatrix with increased line spacing.

Note that ampersand replacement is needed as you want to use & for the matrices.

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\usepackage{etoolbox}

\makeatletter
\let\xsmallmatrix\smallmatrix
\let\endxsmallmatrix\endsmallmatrix
\patchcmd{\xsmallmatrix}{6\ex@}{12\ex@}{}{}
\newenvironment{bxsmallmatrix}
{\left[\xsmallmatrix}
{\endxsmallmatrix\right]}
\makeatother

\begin{document}

$\begin{tikzcd}[ampersand replacement=\&,column sep=huge] k\oplus k^2 \arrow[r,"{\begin{bxsmallmatrix}1&0&0\\0&1&1\\0&0&1\end{bxsmallmatrix}}"] \& k\oplus k^2 \& 0\oplus k \arrow[l,"{\begin{bxsmallmatrix}0&0\\0&1\\0&1\end{bxsmallmatrix}}"'] \end{tikzcd}$

$\begin{tikzcd}[ampersand replacement=\&,column sep=huge] k\oplus k^2 \arrow[r,"{\begin{bsmallmatrix}1&0&0\\0&1&1\\0&0&1\end{bsmallmatrix}}"] \& k\oplus k^2 \& 0\oplus k \arrow[l,"{\begin{bsmallmatrix}0&0\\0&1\\0&1\end{bsmallmatrix}}"'] \end{tikzcd}$

\end{document}


A simple code with tikz-cd and the bsmallmatrix environment from mathtools

\documentclass[11pt]{article}
\usepackage{mathtools}
\usepackage{tikz-cd}

\begin{document}

$\begin{tikzcd}[row sep=1.2cm, column sep=2cm, arrows=-stealth, ampersand replacement=\&] k\oplus k^2\rar{\begin{bsmallmatrix}1 & 0 & 0\\0 & 1 & 1\\0 & 0 & 1\end{bsmallmatrix}} \& k\oplus k^2\& \lar[swap]{\begin{bsmallmatrix}0 & 0\\0 & 1\\ 0 & 1\end{bsmallmatrix}} 0\oplus k \end{tikzcd}$

\end{document}


Edit :

To have control on the horizontal spacing in the matrices, you can use the bmatrix environment, and use the classical tools \arraystretch and \arraycolsep(defaults 1 and 5pt respectively). For instance:

   $\renewcommand{\arraystretch}{0.7}\setlength{\arraycolsep}{3pt} \begin{tikzcd}[row sep=1.2cm, column sep=2cm, arrows=-stealth, ampersand replacement=\&] k\oplus k^2\rar{\begin{bmatrix}1 & 0 & 0\\0 & 1 & 1\\0 & 0 & 1\end{bmatrix}} \& k\oplus k^2\& \lar[swap]{\begin{bmatrix}0 & 0\\0 & 1\\ 0 & 1\end{bmatrix}} 0\oplus k \end{tikzcd}$


yields this diagram:

• It would be very nice to improve the vertical spacing between the matrix elements. To my taste, they are very close each other. Commented Jul 16, 2018 at 18:14
• It's the default in this environment, but I'll fix it in a moment. Commented Jul 16, 2018 at 18:17
• @MarianG.: I've added a code to have another spacing. Commented Jul 16, 2018 at 18:30

It suffices to use the basic tools of the tikz-machinery. In fact, the following code is only a very simple exercise and you can modify it further according to your notion.

\documentclass{standalone}

\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node (A) {$k\oplus k^2$};
\node (B) at ($(A)+(3,0)$) {$k\oplus k^2$};
\node (C) at ($(B)+(3,0)$) {$0\oplus k$};
%
\draw[-stealth]
(A) -- (B)
node[midway,above,scale=.5]
{$\begin{bmatrix} 1& 0& 0\\ 0& 1& 0\\ 0& 0& 1 \end{bmatrix}$};
\draw[-stealth]
(C) -- (B)
node[midway,above,scale=.5]
{$\begin{bmatrix} 0& 0\\ 0& 1\\ 0& 1 \end{bmatrix}$};
\end{tikzpicture}
\end{document}


• @tuce Please, correct the first matrix in the code. I've assumed the unit matrix. Commented Jul 16, 2018 at 17:57
• what should i do to make double arrow ? @Marian G.
– tuce
Commented Jul 16, 2018 at 19:41
• @tuce To double the line, simply add the option double to the \draw-command, i.e., \draw[-stealth,double]. However, I'm not sure about your formulation "double arrow". Commented Jul 17, 2018 at 7:08