# drawing a matrix with its minors

I want to create something like this:

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?

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}


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}


Already been accepted, but this is for Werner

\documentclass{article}

\usepackage{tikz}

\begin{document}

$\left( \begin{tikzpicture}[baseline=(current bounding box.center)] \draw[line width=2pt] plot [smooth,tension=.2] coordinates{(0,-1) (1,-1) (1,0)}; \draw[line width=2pt] plot [smooth,tension=.2] coordinates{(0,-2) (2,-2) (2,0)}; \draw[line width=2pt] plot [smooth,tension=.2] coordinates{(0,-3) (3,-3) (3,0)}; % % \begin{pgfinterruptboundingbox} % \draw[line width=1pt] plot [smooth,tension=1] coordinates{(.5,-.5) (3,0) (5,-.5)}; \draw[](5,-.5) node[right=1pt]{text 1}; % \draw[line width=1pt] plot [smooth,tension=1] coordinates{(1.5,-1.5) (3.4,-1) (5,-1.5)}; \draw[](5,-1.5) node[right=1pt]{text 2}; % \draw[line width=1pt] plot [smooth,tension=1] coordinates{(2.5,-2.5) (4,-2) (5,-2.5)}; \draw[](5,-2.5) node[right=1pt]{text 3}; \end{pgfinterruptboundingbox} \end{tikzpicture} \right)$
\end{document}


Thanks to Gonzalo for the pgfinterruptboundingbox to avoid having to backspace to position the right bracket.

• – Werner May 22 '14 at 2:28
• +1, but that \hspace{-80pt} is really ugly. ;-) – egreg May 22 '14 at 7:38
• @egreg I tried a use as bounding box thing to force the size of the tikzpicture but it didn't want to play :( – David Carlisle May 22 '14 at 8:26
• @egreg beauty is restored – David Carlisle May 22 '14 at 21:21

this is my solution with Tikz.

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\tmark}[1]{\tikz[remember picture, overlay] \node(#1){};}
\begin{document}
\begin{align*}
A =
\left(
\begin{array}{cccc}
a_{11} & a_{12} & a_{13} & a_{14}
\\
a_{21} & a_{22}\tmark{a} & a_{23} & a_{24}
\\
a_{31} & a_{32} & a_{33}\tmark{b} & a_{34}
\\
a_{41} & a_{42} & a_{43} & a_{44}\tmark{c}
\end{array}
\right)
\begin{tikzpicture}[remember picture,overlay]
\draw ($(a)+(0,0.7)$) to ($(a)+(0,-0.2)$) to ($(a)-(1.5,0.2)$);
\draw ($(b)+(0,1.1)$) to ($(b)+(0,-0.2)$) to ($(b)-(2.4,0.2)$);
\draw ($(c)+(0,1.5)$) to ($(c)+(0,-0.2)$) to ($(c)-(3,0.2)$);
%
\draw[-latex, red, thick, out=30, in=180]($(a)-(0.1,0.1)$) to ($(a)+(3,0)$) node[right] {text1};
\draw[-latex, red, thick, out=30, in=180]($(b)-(0.1,0.1)$) to ($(b)+(3,0)$) node[right] {text2};
\draw[-latex, red, thick, out=30, in=180]($(c)-(0.1,0.1)$) to ($(c)+(3,0)$) node[right] {text3};
\end{tikzpicture}
\end{align*}
\end{document}


A solution with pstricks:

\documentclass{article}%

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{array}
\usepackage{mathtools}

\begin{document}

$\psset{angleB=-90, colsep=15pt, rowsep=\baselineskip, linewidth=0.5pt}% \setlength{\arraycolsep}{6pt} \begin{pmatrix} \begin{psmatrix} [name=a11]& [name=a12] & [name=a13] & [name=a14] & [name=a15] & \hspace*{-4mm} \\ [name=a21] & [name=a22] \\ [name=a31] & & [name=a33] \\ [name=a41] & & & [name=a44] \\ [name=a51] & & & & [name=a55] \end{psmatrix} \multido{\I=2 + 1}{4}{\ncangle{a\I1}{a1\I}}% \midAB(a11)(a22){r1} \midAB(a22)(a33){r2} \midAB(a33)(a44){r3} \midAB(a44)(a55){r4} \psset{nodesepA=0pt, nodesepB= 4pt, linestyle=dashed, dash = 2pt 2pt, linewidth=0.3pt, arrows=*-,dotsize = 1.5pt} \multido{\I=1+1}{4}{\nput[labelsep = \dimexpr 100pt-15pt*\I\relax]{0}{r\I}{\Rnode{t\I}{\text{\footnotesize Text \I}}}\ncline{r\I}{t\I}} \end{pmatrix}$

\end{document}


I give another solution where no external package is used. No tikz, no pstricks, only pdfTeX primitives and simple PDF code is used. This solution is only for comparison here.

\def\arrowcc #1 #2 #3 #4 #5 #6 #7{%
% x0 y0 {cx1 cy1 cx2 cy2} x1 y1 {arrow-dir} {text}
\pdfsave\rlap{\pdfliteral{%
.7 w 1 0 0 1 #1 #2 cm 0 0 m #3 #4 #5 c S
q #6 #4 #5 cm 0 6 m 2 0 l -2 0 l h f Q
1 0 0 1 #4 #5 cm 1 0 0 1 10 -3 cm}%
\hbox{#7}}\pdfrestore
}
\def\rightdir{0 -1 1 0}
\def\arrowA{\arrowcc -5 6 {50 50 100 0} 150 0 {\rightdir} }
\def\arrowB{\arrowcc -5 6 {50 50 70 0} 120 0 {\rightdir} }
\def\arrowC{\arrowcc -5 6 {30 40 50 0} 90 0 {\rightdir} }
\def\arrowD{\arrowcc -5 6 {20 30 40 0} 60 0 {\rightdir} }

$$\let\mathstrut=\relax \let\normalbaselines=\relax \baselineskip=0pt \lineskip=-.4pt \delimiterfactor=1000 \def\|{\kern.5em\vrule height9pt depth6pt} \pmatrix{ a_{11} \arrowA{text1} \| & a_{12} \| & a_{13} \| & a_{14} \| \cr \omit\hrulefill \cr a_{21} & a_{22} \arrowB{text2} \| & a_{23} \| & a_{24} \| \cr \multispan2\hrulefill \cr a_{31} & a_{32} & a_{33} \arrowC{text3} \| & a_{34} \| \cr \multispan3\hrulefill \cr a_{41} & a_{42} & a_{43} & a_{44} \arrowD{text4} \| \cr \multispan4\hrulefill }\hbox to50pt{}$$
\end


And the result: