Cross product using the checker method
Here are some modifications that can (hopefully) improve the result:
- I declared a fixed width for the text in the matrix nodes.
- I used the
let
syntax to draw the vertical rules. - I reduced the
inner sep
value for the nodes containing the signs. - I defined a
\checkers
command with a mandatory argument (the name of the matrix) to draw the design. In fact, a seven argument command might be used for the whole construct.
Here's the code
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{fullpage,amsmath}
\newcommand\checkers[1]{%
\draw [BarreStyle=red] (#1-1-1.120) node[SignePlus=red] {$+$} to (#1-3-3.320) ;
\draw [BarreStyle=red] (#1-1-2.120) node[SignePlus=red] {$+$} to (#1-3-4.320) ;
\draw [BarreStyle=red] (#1-1-3.120) node[SignePlus=red] {$+$} to (#1-3-5.320) ;
\draw [BarreStyle=blue] (#1-1-3.35) node[SigneMoins=blue] {$-$} to (#1-3-1.230);
\draw [BarreStyle=blue] (#1-1-4.35) node[SigneMoins=blue] {$-$} to (#1-3-2.230);
\draw [BarreStyle=blue] (#1-1-5.35) node[SigneMoins=blue] {$-$} to (#1-3-3.230);
\draw let \p1 = (#1-3-3.south east), \p2 = ( $ (#1-1-3.north east)!.5!(#1-1-4.north) $ ) in (\p2) -- (\x2,\y1);
\draw let \p1 = (#1-1-1.north west), \p2 = (#1-3-1.south west) in (\p2) -- (\x2,\y1);
}
\tikzset{BarreStyle/.style = {opacity=.4,line width=4mm,line cap=round,color=#1}}
\tikzset{SignePlus/.style = {above left,,opacity=0.8,circle,inner sep=1pt,fill=#1!50}}
\tikzset{SigneMoins/.style = {above right,,opacity=0.8,circle,inner sep=1pt,fill=#1!50}}
\begin{document}
\begin{figure}
\tikzset{node style ge/.style={circle}}
\centering
\begin{tikzpicture}[baseline=(A.center)]
\matrix (A) [matrix of math nodes, nodes = {node style ge},column sep=0 mm,nodes={text width=1em,align=right}]
{ i & j & k & i & j \\
3 & -2 & 2 & 3 & -2 \\
31 & 2 & 61 & 3 & 2 \\
};
\checkers{A}
\end{tikzpicture}\\[1em]
\begin{tikzpicture}[baseline=(B.center)]
\matrix (B) [matrix of math nodes, nodes = {node style ge},column sep=0 mm,nodes={text width=1em,align=right}]
{ i & j & k & i & j \\
13 & -2 & 25 & 13 & -2 \\
3 & -18 & 1 & 3 & 2 \\
};
\checkers{B}
\end{tikzpicture}
\end{figure}
\end{document}
If this will be always used to indicate cross-products, then a command with seven arguments (the six coordinates and the matrix name) can be defined; something along these lines:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{fullpage,amsmath}
\newcommand\checkers[7]{%
\begin{tikzpicture}[baseline=(#1.center)]
\tikzset{BarreStyle/.style = {opacity=.4,line width=4mm,line cap=round,color=##1}}
\tikzset{SignePlus/.style = {above left,opacity=0.8,circle,inner sep=1pt,fill=##1!50}}
\tikzset{SigneMoins/.style = {above right,opacity=0.8,circle,inner sep=1pt,fill=##1!50}}
\tikzset{node style ge/.style={circle}}
\matrix (#1) [matrix of math nodes, nodes = {node style ge},column sep=0 mm,nodes={text width=1.8em,align=right,font=\footnotesize},ampersand replacement = \&]
{ i \& j \& k \& i \& j \\
#2 \& #3 \& #4 \& #2 \& #3 \\
#5 \& #6 \& #7 \& #5 \& #6 \\
};
\draw [BarreStyle=red] (#1-1-1.120) node[SignePlus=red] {$+$} to (#1-3-3.320) ;
\draw [BarreStyle=red] (#1-1-2.120) node[SignePlus=red] {$+$} to (#1-3-4.320) ;
\draw [BarreStyle=red] (#1-1-3.120) node[SignePlus=red] {$+$} to (#1-3-5.320) ;
\draw [BarreStyle=blue] (#1-1-3.35) node[SigneMoins=blue] {$-$} to (#1-3-1.230);
\draw [BarreStyle=blue] (#1-1-4.35) node[SigneMoins=blue] {$-$} to (#1-3-2.230);
\draw [BarreStyle=blue] (#1-1-5.35) node[SigneMoins=blue] {$-$} to (#1-3-3.230);
\draw let \p1 = (#1-3-3.south east), \p2 = ( $ (#1-1-3.north east)!.5!(#1-1-4.north) $ ) in (\p2) -- (\x2,\y1);
\draw let \p1 = (#1-1-1.north west), \p2 = (#1-3-1.south west) in (\p2) -- (\x2,\y1);\end{tikzpicture}
}
\begin{document}
\begin{figure}
\centering
\checkers{A}{3}{-2}{2}{31}{2}{61}\\[1em]
\checkers{B}{13}{-2}{25}{3}{-18}{1}
\end{figure}
\end{document}
Just another solution using fit
, rotate fit
and pgfonlayer
...
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,backgrounds,fit}
\usepackage{amsmath}
\newcommand\checkers[1]{
\begin{pgfonlayer}{background}
\tikzset{
bar style/.style={inner ysep=-.1em,inner xsep=1em,rounded corners=.8em},
fillop/.style={fill=##1,fill opacity=.3},
sign/.style={circle,inner sep=.2em,fillop=##1,text opacity=1},
}
\foreach \posa in {1,2,3}{
\pgfmathsetmacro{\posb}{\posa + 2}
\node[bar style=red,rotate fit=-45,
fit=(#1-1-\posa)(#1-3-\posb),fillop=red,
label={[sign=red]west:$+$}]{};
\node[bar style=red,rotate fit=45,
fit=(#1-1-\posb)(#1-3-\posa),fillop=blue,
label={[sign=blue]east:$-$}]{};
}
\draw let \p1=($(#1-1-3)!.5!(#1-1-4)$) in
(\p1 |- #1.north) -- (\p1 |- #1.south);
\draw (#1.north west) -- (#1.south west);
\end{pgfonlayer}
}
\begin{document}
\begin{tikzpicture}
\matrix (A)
[matrix of math nodes,inner sep=0pt,
nodes={minimum size=2.5em,inner sep=0pt}]
{
i & j & k & i & j \\
3 & -2 & 2 & 3 & -2 \\
61 & 2 & 61 & 3 & 2 \\
};
\checkers{A}
\end{tikzpicture}
{\footnotesize%
\begin{tikzpicture}
\matrix (B)
[matrix of math nodes,inner sep=0pt,
nodes={minimum size=2.5em,inner sep=0pt}]
{
i & j & k & i & j \\
13 & -2 & 125 & 13 & -2 \\
3 & -18 & 1 & 3 & 2 \\
};
\checkers{B}
\end{tikzpicture}%
}
\end{document}
Here is results with different font sizes: