I'm trying to explain the Sarrus method and to draw the lines between nodes I'm using the tikz and matrix packages. However, when the delimiters are not parentheses but vertical bars (and also redefining the rows and columns separations) they become too long. I've tried this solution but it didn't work out.
I would like them to have the same length as the vmatrix matrix delimiters that I have written in the following code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{mathtools}
\usepackage{float}
\begin{document}
\[
\det(A) = \begin{vmatrix*}[r]
a & b & c\\
d & e & f\\
g & h & i
\end{vmatrix*}
\]
\begin{figure}[H]
\centering
$ \det(A) =$
\begin{tikzpicture}[
baseline=(A-2-1.base),
every left delimiter/.style={xshift=.8em},
every right delimiter/.style={xshift=-.8em},
]
\matrix [
matrix of math nodes,
row sep={0.43cm,between origins},
column sep={0.6cm,between origins},
left delimiter=|,
right delimiter=|] (A)
{
a & b & c \\
d & e & f \\
g & h & i \\
};
\draw[line width=0.6pt] (A-1-1.center) -- (A-3-3.center);
\draw[line width=0.6pt] (A-2-1.center) -- (A-3-2.center) -- (A-1-3.center) -- (A-2-1.center)--cycle;
\end{tikzpicture}
\end{figure}
\end{document}

\tikzmarknodewas added. If you update your TeX distribution (or download the latest version of the library), you will no longer get this error. (This is why I added "(new)" beforetikzmark, but yes, "new" is relative.) – Jan 18 '19 at 19:49