1

I'm using the same codes as my the answer of my previous question

    \documentclass[12pt,a4paper]{report}
    \usepackage{amsfonts,amsmath,amssymb,amsthm,tikz}
    \usetikzlibrary{calc,matrix}
\begin{document}
\begin{align*}
D &=
\begin{tikzpicture}[
baseline=-\the\dimexpr\fontdimen22\textfont2\relax,
strip/.style = {
    draw=#1,%color
    line width=1em, opacity=0.2,
    shorten <=-2mm,shorten >=-2mm,
                            },
                    ]
\matrix (mtrx)  [matrix of math nodes,
                 column sep=1em,
                 nodes={text height=1ex,text width=2ex},
                 ampersand replacement=\&]
{
|[red]|+  \& |[red]|+  \& |[red]| +
 \\[3.3mm,between origins]
a_1 \& b_1 \& c_1 \& a_1 \& a_2         \\
a_2 \& b_2 \& c_2 \& a_2 \& b_2         \\
a_3 \& b_3 \& c_3 \& a_3 \& b_3         \\
|[blue]|- \& |[blue]|- \& |[blue]|- \\
};
\draw[thick]  (mtrx-4-1.south west) -- (mtrx-2-1.north west);
\draw[thick] (mtrx-4-3.south east)  -- (mtrx-2-3.north east);
\path[draw,strip=blue]
    (mtrx-4-1.center) edge (mtrx-2-3.center)
    (mtrx-4-2.center) edge (mtrx-2-4.center)
    (mtrx-4-3.center)  --  (mtrx-2-5.center);
\path[draw,strip=red]
    (mtrx-2-1.center) edge (mtrx-4-3.center)
    (mtrx-2-2.center) edge (mtrx-4-4.center)
    (mtrx-2-3.center)  --  (mtrx-4-5.center);
\end{tikzpicture} \\
 &= a+b+c\dots
\end{align*}
\end{document}

However I want to replace

enter image description here

If I replace in the codes

\begin{tikzpicture}[
baseline=-\the\dimexpr\fontdimen22\textfont2\relax,
strip/.style = {
    draw=#1,%color
    line width=1em, opacity=0.2,
    shorten <=-2mm,shorten >=-2mm,
                            },
                    ]
\matrix (mtrx)  [matrix of math nodes,
                 column sep=1em,
                 nodes={text height=1ex,text width=2ex},
                 ampersand replacement=\&]
{
|[red]|+  \& |[red]|+  \& |[red]| +
 \\[3.3mm,between origins]
a_1 \& b_1 \& c_1 \& a_1 \& a_2         \\
a_2 \& b_2 \& c_2 \& a_2 \& b_2         \\
a_3 \& b_3 \& c_3 \& a_3 \& b_3         \\
|[blue]|- \& |[blue]|- \& |[blue]|- \\
};
\draw[thick]  (mtrx-4-1.south west) -- (mtrx-2-1.north west);
\draw[thick] (mtrx-4-3.south east)  -- (mtrx-2-3.north east);
\path[draw,strip=blue]
    (mtrx-4-1.center) edge (mtrx-2-3.center)
    (mtrx-4-2.center) edge (mtrx-2-4.center)
    (mtrx-4-3.center)  --  (mtrx-2-5.center);
\path[draw,strip=red]
    (mtrx-2-1.center) edge (mtrx-4-3.center)
    (mtrx-2-2.center) edge (mtrx-4-4.center)
    (mtrx-2-3.center)  --  (mtrx-4-5.center);
\end{tikzpicture}

by

\begin{tikzpicture}[>=stealth]
    \matrix [%
      matrix of math nodes,
      column sep=1em,
      row sep=1em
    ] (sarrus) {%
      a_{11} & a_{12} & a_{13} & a_{11} & a_{12} \\
      a_{21} & a_{22} & a_{23} & a_{21} & a_{22} \\
      a_{31} & a_{32} & a_{33} & a_{31} & a_{32} \\
    };
\path ($(sarrus-1-1.north west)-(0.5em,0)$) edge ($(sarrus-3-1.south west)-(0.5em,0)$)
      ($(sarrus-1-3.north east)+(0.5em,0)$) edge ($(sarrus-3-3.south east)+(0.5em,0)$)
      (sarrus-1-1)                          edge            (sarrus-2-2)
      (sarrus-2-2)                          edge[-&gt;]        (sarrus-3-3)
      (sarrus-1-2)                          edge            (sarrus-2-3)
      (sarrus-2-3)                          edge[-&gt;]        (sarrus-3-4)
      (sarrus-1-3)                          edge            (sarrus-2-4)
      (sarrus-2-4)                          edge[-&gt;]        (sarrus-3-5)
      (sarrus-3-1)                          edge[dashed]    (sarrus-2-2)
      (sarrus-2-2)                          edge[-&gt;,dashed] (sarrus-1-3)
      (sarrus-3-2)                          edge[dashed]    (sarrus-2-3)
      (sarrus-2-3)                          edge[-&gt;,dashed] (sarrus-1-4)
      (sarrus-3-3)                          edge[dashed]    (sarrus-2-4)
      (sarrus-2-4)                          edge[-&gt;,dashed] (sarrus-1-5);

\foreach \c in {1,2,3} {\node[anchor=south] at (sarrus-1-\c.north) {$+$};};
\foreach \c in {1,2,3} {\node[anchor=north] at (sarrus-3-\c.south) {$-$};};

\end{tikzpicture}

It does not work.

Student
  • 1,134
  • 2
  • 9
  • 27
  • In the previous code there is ampersand replacement=\&. Could be this the problem? – vi pa Jun 26 '21 at 21:33
  • And you can have a look at this one too. – SebGlav Jun 26 '21 at 22:49
  • Just like with my code, you need to use ampersand replacement (as already mentioned by @vipa), and in addition you need to remove the empty lines. Didn't think about that earlier, but empty lines are not allowed in math environments. See e.g. https://tex.stackexchange.com/questions/230338/ – Torbjørn T. Jun 27 '21 at 09:40
  • @TorbjørnT. I replaced \&= by =\& but it does not complile – Student Jun 27 '21 at 09:46
  • Huh? That has nothing to do with what I said above. Did you remove the empty lines before \path and \foreach? Did you add ampersand replacement=\& to the options of the matrix? – Torbjørn T. Jun 27 '21 at 09:58
  • Don't use \& outside the tikzpicture, only inside. – Torbjørn T. Jun 27 '21 at 09:59
  • I'm so sorry @TorbjørnT. since I tired you. I will be really greatful if you add this answer to the answer of your previous question. I deleted empty lines but I don't understand how to add ampersand replacement=\& to the options of the matrix – Student Jun 27 '21 at 10:04
  • Please look at the code in my original answer - where in that code do you find ampersand replacement? "Options" in this context is the list of settings that you add in [] after \matrix. – Torbjørn T. Jun 27 '21 at 10:12
  • Yes I added it and I'm trying to compilate but till now it does not work. – Student Jun 27 '21 at 10:14
  • @TorbjørnT. The error message indicate that there is $. I removed $ but it does not work also. – Student Jun 27 '21 at 10:18
  • Look, I'm not at my computer now, but meanwhile, compare the tikzpicture from my code with your new one, and change the new one accordingly. I cannot guess how you managed to get an error about dollar signs. – Torbjørn T. Jun 27 '21 at 10:36
  • Since 4 hours I'm trying. I will be very greatful if you can help me later. Not necessarely today – Student Jun 27 '21 at 10:52
  • @TorbjørnT. I followed all your recommondations. The error message is long ``l.37 \end{align*}

    ? ! Undefined control sequence. \pgf@matrix@last@nextcell@options

    l.37 \end{align*}

    ? Missing character: There is no a in font nullfont! ! Missing $ inserted.

    $ l.37 \end{align*}

    ? ``

    – Student Jun 27 '21 at 11:51

1 Answers1

2

For fun, another way using blkarray, an align* environment and pstricks:

\documentclass[svgnames]{article}
\usepackage{blkarray}
\usepackage{amsmath}
\usepackage{pst-node}

\begin{document}

\begin{align} D & = \begin{blockarray}{ccccc} \color{red} + & \color{red} + & \color{red} + \ \begin{block}{|ccc|cc} \Rnode{a1}{a_{11}} &\Rnode{b1}{ a_{12}} & \Rnode{c1}{a_{13}} & \Rnode{A1}{a_{11}} & \Rnode{B1}{a_{12}} \ \Rnode{a2}{ a_{21}} & \Rnode{b2}{a_{22}} & \Rnode{c2}{a_{23}} & \Rnode{A2}{a_{21} }& a_{22} \ \Rnode{a3}{a_{31}} & \Rnode{b3}{a_{32}} & \Rnode{c3}{a_{33}} & \Rnode{A3}{a_{31}} & \Rnode{B3}{a_{32}} \ \end{block} \color{blue} - & \color{blue} - & \color{blue} - \end{blockarray} \[-3ex] & = a_{11} a_{22}a_{33} + a_{12}a_{23}a_{31} + \dots \psset{linewidth=0.5pt, nodesepA=1pt, nodesepB =1.5pt, arrowinset=0.1} \foreach \s/\t in {a1/b2,b1/c2,c1/A2} {\ncline{-}{\s}{\t}} \foreach \s/\t in {b2/c3,c2/A3,A2/B3} {\ncline{->}{\s}{\t}} \psset{linestyle=dashed, dash=3pt 2pt} \foreach \s/\t in {a3/b2,b3/c2,c3/A2} {\ncline{-}{\s}{\t}} \foreach \s/\t in {b2/c1,c2/A1,A2/B1} {\ncline{->}{\s}{\t}} % \end{align}

\end{document}

enter image description here

Bernard
  • 271,350
  • Thanks Professor for your great answer but I fails to compilate – Student Jun 27 '21 at 08:23
  • @Student: How did you compile? – Bernard Jun 27 '21 at 08:48
  • I just copy and paste your codes but I does not work – Student Jun 27 '21 at 08:56
  • l.26 \end{align*}

    ? ! Undefined control sequence. \c@lor@to@ps ->\PSTricks _Not_Configured_For_This_Format l.26 \end{align*}

    ? ! Undefined control sequence. \XC@usec@lor ...string \color@ #1#2\endcsname @@ \fi \space l.26 \end{align*}

    ? ! Undefined control sequence. \c@lor@to@ps ->\PSTricks _Not_Configured_For_This_Format l.26 \end{align*}

    – Student Jun 27 '21 at 09:00
  • the error message is so long – Student Jun 27 '21 at 09:00
  • You have to know that pdflatex can't compile pstricks code, because it doesn't have the necessary tools to make the computations required by postscript. The basic way is latex > dvips > pstopdf. Simpler: compile with xelatex -shell-escape. – Bernard Jun 27 '21 at 09:02
  • I'm sorry since I don't understand. I always compile and get the PDF. I work with winedit 5.6 – Student Jun 27 '21 at 09:09
  • WinEdt 5.6? That's a very old version. Current version is 10.3. Nevertheless, I suppose you have a way to choose the compiler in the taskbar. – Bernard Jun 27 '21 at 09:32
  • Yes it is old but in general I don't find problems in compilations. The only problem is in your answer. My question is unfortunately closed and i cannot receive may be a more simpler answer. Thank you Professor for helping me – Student Jun 27 '21 at 09:35
  • Anyway, I suppose you have a way to launch xelatex even with this version? – Bernard Jun 27 '21 at 09:40
  • I'm sorry my field is Math. I'm beginner in Latex. I never hear about xelatex – Student Jun 27 '21 at 09:54
  • My field is math too. It gives the possibility to use any font that's on you computer (for text), with a package named fontspec. – Bernard Jun 27 '21 at 10:15