# Big block matrix with tikz

I know this is very similar to plenty of questions.

The matrix below s actually bigger, so I realized that I had to use tikz. In this array, A, A',…,L', T are square matrices, and I filled with zeros the right half, although the original matrix doesn't have these trivial entries, so I cannot remove them (don't try to fix the entries in the right side, because the spacing is ok when I introduce their actual values)

• Is there a less ugly way to write this block matrix?
• I'm sure there is a better way to display this tensor product in the non-zero block below, because, as it is displayed, it is not readable. I mean, it seems that \otimes T is multiplying only the matrix L!

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}

\begin{document}

\begin{tikzpicture}[node distance=-1ex]
\matrix (mymatrix) [matrix of math nodes,left delimiter={(},right
delimiter={)}]
{ 0  &  0 & A&  A'  &  0  &  0  &  0  &  0 & 0 & 0 &  0  &  0  &  0  & 0  &  0  &  0  &  0&0 &\!\!\!\!\! \\
0  &  0  &  B' & B\,\, &  0  &  0  &  0  &  0 & 0 & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
C &  C'  &  0  &  0  &  0  &  0  &  0  &  0 & 0 & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
D' & D &  0  &  0  &  0  &  0  &  0  &  0 & 0 & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  0  &  0  &  K  &  K' &  & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  0  &  0  &  L'  & L  & \!\!\!\otimes T & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  M  &  M'  &  0   &0  &   &  0  &  0  &  0  & 0  &  0  &  0  &  0  & 0&0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  N'  &  N  &  0  & 0  &   &  0  &  0  &  0  & 0  &  0  &  0  &  0  & 0&0&\!\!\!\!\!\\
};
\draw[blue,dashed] (mymatrix-4-1.south west) -- (mymatrix-4-4.south east);
\draw[blue,dashed] (mymatrix-1-4.north east) -- (mymatrix-4-4.south east);
\draw[red,dashed] (mymatrix-4-4.south east) -- (mymatrix-4-10.south west);
\draw[red,dashed] (mymatrix-5-4.north east) -- (mymatrix-8-4.south east);
\draw[red,dashed] (mymatrix-4-10.south west) -- (mymatrix-8-10.south west);
\draw[red,dashed] (mymatrix-8-4.south east) -- (mymatrix-8-10.south west);
\end{tikzpicture}
\end{document}

-
In the tensor product, you want to indicate the product of T and exactly what part? – Gonzalo Medina Sep 18 '12 at 22:33
There is a square antidiagonal matrix, {{0 & 0& K & K'},{0 & 0 & L' & L},{M & M' & 0 &0},{N' & N & 0 & 0}} (just the matrix that remains in the red rectangle by forgetting the T) and all this matrix is tensorially multiplied by T. So, perhaps if I just could lower the \otimes T a little without modifying other rows...? or make some brackets that imply that it is all the matrix which it's been multiplied by T? – c.p. Sep 18 '12 at 23:01

Some matrices are not meant to be typeset.

You have specifically mentioned not to fiddle with the right part but I can't see any special treatment as white spaces are gobbled in the math mode and you have enabled it via matrix of math nodes.

Anyway, here is an idea.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,tikz}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}

\begin{document}
We regret to state that we can not publish the following matrix in any journal in its current state. We
encourage the authors leave these all behind.

$$\begin{pmatrix} \begin{tikzpicture}[every node/.style={minimum width=1.5em}] \matrix (m1) [matrix of math nodes] { 0 & 0 & A & A' \\ 0 & 0 & B' & B \\ C & C' & 0 & 0 \\ D' & D & 0 & 0 \\ }; \matrix (m2) at (m1-4-4.south east) [anchor=m2-1-1.north west, matrix of math nodes] { 0 & 0 & K & K' \\ 0 & 0 & L' & L \\ M & M' & 0 & 0 \\ N' & N & 0 & 0 \\ }; \node[scale=2] at (m1 |- m2) {0}; \node[scale=2,anchor=west] (kron) at ([xshift=-5mm]m2.east) {\otimes T}; \node[scale=2] at (m1 -| m2-1-4) {0}; \matrix (m3) at ([xshift=5pt]kron.east |- m1-1-4.north east) [matrix of math nodes,anchor=m3-1-1.north west] { A' & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & B' & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & C' & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & D' & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & E' & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & ASD' & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & H & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & G & I'0\\ }; \draw (m1-1-4.north east) -- (m1-1-4.north east |- m2-4-1.south west); \draw (m1-1-4.north east -| m3.west) -- (m3.west |- m3-8-1.south east); \draw (m1-4-1.south west) -- (m3-4-9.south east); \end{tikzpicture} \end{pmatrix}$$
\end{document}


-
OK, that is really helpful. And yes, I understand it's better to specify the matrix by smaller blocks. It's for a beamer; I actually want to convince that I have to dramatically abuse of notation, in order not to see this ugly expressions all time. Thanks again! – c.p. Sep 18 '12 at 23:37
@JorgeCampos My pleasure. I also know that sometimes ugly solution is the most pragmatic solution. – percusse Sep 18 '12 at 23:41
@percusse Can you explain a bit how the positioning of the three \node commands does what it does? For example, the at (m1 |- m2). – lpdbw Jul 24 '13 at 12:06

I just introduced three minor changes, but I think they contribute to improve the aspect: the blue vertical dashed line it's now really vertical; I moved the tensor product with T down so as to imply product with all the block to its left; I used {}\otimes T to get the proper spacing around \otimes.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}

\begin{document}

\begin{tikzpicture}[node distance=-1ex]
\matrix (mymatrix) [matrix of math nodes,left delimiter={(},right
delimiter={)}]
{ 0  &  0 & A&  A'  &  0  &  0  &  0  &  0 & 0 & 0 &  0  &  0  &  0  & 0  &  0  &  0  &  0&0 &\!\!\!\!\! \\
0  &  0  &  B' & B\,\, &  0  &  0  &  0  &  0 & 0 & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
C &  C'  &  0  &  0  &  0  &  0  &  0  &  0 & 0 & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
D' & D &  0  &  0' &  0  &  0  &  0  &  0 & 0 & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  0  &  0  &  K  &  K' & \phantom{00} & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  0  &  0  &  L'  & L  & & 0  &  0  &  0  &  0  & 0  &  0  &  0  &  0  &0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  M  &  M'  &  0   &0  &   &  0  &  0  &  0  & 0  &  0  &  0  &  0  & 0&0&\!\!\!\!\!\\
0  &  0  &  0  &  0  &  N'  &  N  &  0  & 0  &   &  0  &  0  &  0  & 0  &  0  &  0  &  0  & 0&0&\!\!\!\!\!\\
};
\draw[blue,dashed] (mymatrix-4-1.south west) -- (mymatrix-4-4.south east);
\draw[blue,dashed] (mymatrix-1-4.north east) -- (mymatrix-5-4.north east -| mymatrix-1-4.south east);
\draw[red,dashed] (mymatrix-4-4.south east) -- (mymatrix-4-10.south west);
\draw[red,dashed] ([xshift=3pt]mymatrix-5-4.north east) -- ([xshift=3pt]mymatrix-8-4.south east);
\draw[red,dashed] (mymatrix-4-10.south west) -- (mymatrix-8-10.south west);
\draw[red,dashed] ([xshift=3pt]mymatrix-8-4.south east) -- (mymatrix-8-10.south west);
\node[xshift=8pt] at (mymatrix-6-8.south east) {${}\otimes T$};
\end{tikzpicture}
\end{document}


-
this is nice as well! thank you. It really improved. – c.p. Sep 18 '12 at 23:49