# Drawing lines along entries of matrices

I would like to demonstrate the special formula for the determinants of 3 by 3 matrices, http://www.purplemath.com/modules/determs2.htm. That is

\documentclass{article}
\begin{document}
$$\begin{array}{ccc|cc} a & b & c & a & b\\ d & e & f & d & e\\ g & h & i & g & h \end{array}.$$
\end{document}


adding two columns and draw diagonal lines. In the question, Draw a vertical line over the entries of a column in an array, it is answered how to draw vertical lines. The method I believe can be applied to my case. But I am wondering if there is any recent dedicated package that handles this.

-
duplicate:tex.stackexchange.com/questions/30032/… – kba Feb 14 at 4:21
@kba: I am hereby saying that this cannot be done by the previous answers. I am in fact looking for if there has been a development of a dedicated package for this. – Youngsu Feb 14 at 5:49
@Andrew That link is already in my original post. – Youngsu Feb 14 at 5:49

Here is a quick hack using a matrix of math nodes and tikz:

Code

\documentclass[border=5mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[auto]
\matrix (M)[matrix of math nodes,row sep=1cm,column sep=16mm]{
a & b & c & a & b\\ d & e & f & d & e\\ g & h & i & g & h\\&&[blue]adi&[red]-bfg&[blue]cdh\\
};
\draw[blue](M-1-1)--(M-2-2)--(M-3-3)--(M-4-3);
\draw[blue](M-1-2)--(M-2-3)--(M-3-4)--(M-4-4);
\draw[blue](M-1-3)--(M-2-4)--(M-3-5)--(M-4-5);
\end{tikzpicture}
\end{document}

-
Thank you very much. What I wanted was (M-1-1)--(M-3-3) in your code. This is very helpful. – Youngsu Feb 14 at 7:43