沿著矩陣的條目畫線

沿著矩陣的條目畫線

我想示範 3 x 3 矩陣行列式的特殊公式,http://www.purplemath.com/modules/determs2.htm。那是

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

新增兩個欄位並繪製對角線。在問題中,在數組中列的條目上繪製一條垂直線,回答如何繪製垂直線。我相信這個方法可以應用在我的案例中。但我想知道是否有最近專用處理這個的包。

答案1

matrix of math nodes這是使用and 的快速技巧蒂克茲:

在此輸入影像描述

程式碼

\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

{NiceMatrix}nicematrix≥ 2023-03-31 的 6.17)。

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

您需要多次編譯(因為nicematrix使用 PGF/Tikz 節點)。

上述程式碼的輸出

相關內容