3

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.

Youngsu
  • 278
  • duplicate:http://tex.stackexchange.com/questions/30032/highlighting-diagonal-of-a-square-matrix – kba Feb 14 '16 at 04: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 '16 at 05:49
  • @Andrew That link is already in my original post. – Youngsu Feb 14 '16 at 05:49

2 Answers2

5

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

enter image description here

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}
2

A solution with {NiceMatrix} of nicematrix (≥ 6.17 of 2023-03-31).

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{center} \NiceMatrixOptions { pgf-node-code = \pgfsetfillcolor{white} \pgfusepathqfill }

\pgfset{nicematrix/cell-node/.style = { inner sep = 3pt } }

\renewcommand{\arraystretch}{2} \setlength{\tabcolsep}{3pt} $\begin{NiceMatrix}[columns-width=auto] \CodeBefore [create-cell-nodes] \begin{tikzpicture} [blue] \draw (1-1.base) -- (3.5-|3.5) ; \draw (1-2.base) -- (3.5-|4.5) ; \draw (1-3.base) -- (3.5-|5.5) ;
\draw [shorten > = 1mm] (3-3) -- (4-3) ; \draw [shorten > = 1mm] (3-4) -- (4-4) ; \draw [shorten > = 1mm] (3-5) -- (4-5) ; \end{tikzpicture} \Body a & b & c & a & b\ d & e & f & d & e\ g & h & i & g & h\ & &\color{blue}adi&\color{red}-bfg&\color{blue}cdh\ \end{NiceMatrix}$ \end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

F. Pantigny
  • 40,250