[Tex/LaTex] drawing a matrix with its minors

matricestikz-matrix

I want to create something like this:

a busy cat

This should be a matrix and I want to consider its minors which are drawn by __|. I want to draw also a line from one minor to a place outside of the matrix to explain something ('text').

After a short internet search I've tried some stuff and got a very ugly matrix:

\begin{align*}
\begin{pmatrix}
\rule[-.5ex]{1em}{0.4pt}|\rule[-.5ex]{1em}{0.pt}| \rule[-.5ex]{1.em{0.0pt}|  \rule[-.5ex]{1.em}{0.0pt}| \\
\rule[-.5ex]{2.3em}{0.4pt}| \rule[-.5ex]{1.em}{0.0pt}| \rule[-.5ex]{1.em}{0.0pt}|  \\
\rule[-.5ex]{3.6em}{0.4pt}| \rule[-.5ex]{1.em}{0.0pt}| \\
\rule[-.5ex]{4.9em}{0.4pt}|   
\end{pmatrix}\end{align*}

How can you do it better (tikz?) and how do you get those lines from a minor to a place outside the matrix?

Best Answer

One option using a matrix of math nodes (change the settings, colorts, according to your needs):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\[
\begin{tikzpicture}[baseline,>=latex]
\matrix[
  matrix of math nodes,
  nodes in empty cells,
  left delimiter=(,
  right delimiter=),
  nodes={text height=8pt,text depth=2pt,text width=10pt}
] (mat)
{
& & &  \\
& & &  \\
& & &  \\
& & &  \\
};
\foreach \Valor in {1,...,4}
  \draw (mat-\Valor-1.south west) -| (mat-1-\Valor.north east);
\draw[->] 
  (mat-1-1.center) 
    to[out=60,in=150] 
  ([xshift=1cm]mat.east|-mat-1-1) 
    node[anchor=west] {some text}
  ;  
\draw[->] 
  (mat-2-2.center) 
    to[out=60,in=180] 
  ([xshift=1cm]mat.east|-mat-2-2) 
    node[anchor=west] {some text}
  ;  
\draw[->] 
  (mat-3-3.center) 
    to[out=60,in=180] 
  ([xshift=1cm]mat.east|-mat-3-3) 
    node[anchor=west] {some text}
  ;  
\draw[->] 
  (mat-4-4.center) 
    to[out=60,in=180] 
  ([xshift=1cm]mat.east|-mat-4-4) 
    node[anchor=west] {some text}
  ;  
\end{tikzpicture}
\]

\end{document}

enter image description here

One can even simplify to just one \foreach loop:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\[
\begin{tikzpicture}[baseline,>=latex]
\matrix[
  matrix of math nodes,
  nodes in empty cells,
  left delimiter=(,
  right delimiter=),
  nodes={text height=8pt,text depth=2pt,text width=10pt}
] (mat)
{
& & &  \\
& & &  \\
& & &  \\
& & &  \\
};
\foreach \Valor/\Texto in 
  {
  1/{Some text 1},
  2/{Some text 2},
  3/{Some text 3},
  4/{Some text 4}
  }
{
\draw (mat-\Valor-1.south west) -| (mat-1-\Valor.north east);
\draw[->] 
  (mat-\Valor-\Valor.center) 
    to[out=60,in=180] 
  ([xshift=1cm]mat.east|-mat-\Valor-\Valor) 
    node[anchor=west] {\Texto}
  ;  
}
\end{tikzpicture}
\]

\end{document}

enter image description here

Related Question