2

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

I'd use the (new) tikzmark library for that. Then the matrices look (apart from the lines) like twins.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{mathtools}

\begin{document}
    \[
    \det(A) = \begin{vmatrix*}[r]
    a & b & c\\
    d & e & f\\
    g & h & i
    \end{vmatrix*}
    \]
    \[
    \det(A) = \begin{vmatrix*}[r]
    \tikzmarknode{a}{a} & b & \tikzmarknode{c}{c}\\
    \tikzmarknode{d}{d} & e & f\\
    g & \tikzmarknode{h}{h} & \tikzmarknode{i}{i}
    \end{vmatrix*}
    \]
    \begin{tikzpicture}[overlay,remember picture]
    \draw[line width=0.6pt] (a.center) -- (i.center)
    (d.center) -- (c.center) -- (h.center) -- cycle;
    \end{tikzpicture}
\end{document}

enter image description here

  • By compiling that code I get the error 'Undefined control sequence \tikzmarknode'. Weird :/ – Martín Jan 18 at 19:48
  • @Martín Yes, there has been an update of the library last year, in which \tikzmarknode was 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)" before tikzmark, but yes, "new" is relative.) – user121799 Jan 18 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.