行列の要素に沿って線を引く

行列の要素に沿って線を引く

3行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}

2つの列を追加し、対角線を描きます。質問では、配列内の列のエントリに垂直線を引く垂直線の描き方についての回答です。この方法は私のケースにも適用できると思います。しかし、最近の献身これを処理するパッケージ。

答え1

matrix of math nodesここでは、とを使用した簡単なハックを紹介します。ティックズ:

ここに画像の説明を入力してください

コード

\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

(2023-03-31 の 6.17 以上){NiceMatrix}のソリューション。nicematrix

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

複数のコンパイルが必要です ( nicematrixPGF/Tikz ノードを使用するため)。

上記コードの出力

関連情報