0

I have to highlight the ith row and jth column which are removed from a matrix to form its minor as depicted in the pictureenter image description here

My try is this, but I don't know how to highlight..

    \documentclass[preview, border=1pt, convert={outext=.png}]{standalone}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{braket}
\usepackage[table]{xcolor}
\newcommand\x{\times}
\newcommand\y{\cellcolor{green!10}}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{equation*}
    A = \det\left(\begin{array}{cccc}
    \rowcolor{red!20}
    a_{11}  & \ldots  & a_{1j} & \ldots & a_{1n} \\
    \ldots   & \ldots & \ldots & \ldots & \ldots \\
   \rowcolor{blue!20}
    a_{1j}  & \ldots   & a_{ij} & \ldots & a_{in} \\
    \ldots   & \ldots & \ldots & \ldots & \ldots \\
    a_{n1}  &  \ldots  & a_{nj} & \ldots & a_{nm}\\
  \end{array}\right)
\end{equation*}
\end{document}

1 Answers1

0

With tikzmark you can declare stuff nodes, with tikz you can daw boxes around nodes, and eso-pic allows you to shuffle it on the background.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit}
\usepackage{eso-pic}
\begin{document}
\[A = \det\left(\begin{array}{cccc} a_{11} & \tikzmarknode{a12}{a_{12}} & \ldots & a_{1n}  \\ 
    \tikzmarknode{a21}{a_{21}} & a_{22} & \ldots & \tikzmarknode{a2n}{a_{2n}}  \\
    \ldots & \ldots & \ldots & \ldots \\
    a_{n1} & \tikzmarknode{an2}{a_{n2}} & \ldots & a_{nn}  \\
    \end{array}\right)\]
\AddToShipoutPictureBG*{\begin{tikzpicture}[overlay,remember picture]
\node[fit=(a12) (an2),draw=red,fill=red,fill opacity=0.2]{};
\node[fit=(a21) (a2n),draw=blue,fill=blue,fill opacity=0.2]{};
\end{tikzpicture}}  

\end{document}

enter image description here

Or

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit}
\usepackage{eso-pic}
\begin{document}
\[A = \det\begin{pmatrix} a_{11} & \cdots & \tikzmarknode{a1i}{a_{1i}} & \cdots & a_{1n}  \\ 
    \vdots & \ddots & \vdots & \reflectbox{$\ddots$} & \vdots \\
    \tikzmarknode{aj1}{a_{j1}} & \cdots & a_{ji} & \cdots & \tikzmarknode{ajn}{a_{jn}}  \\
    \vdots & \reflectbox{$\ddots$} & \ldots & \ddots & \vdots \\
    a_{n1} & \cdots &\tikzmarknode{ani}{a_{ni}} & \cdots & a_{nn}  \\
    \end{pmatrix}
\]
\AddToShipoutPictureBG*{\begin{tikzpicture}[overlay,remember picture]
\node[fit=(a1i) (ani),draw=red,fill=red,fill opacity=0.2]{};
\node[fit=(aj1) (ajn),draw=blue,fill=blue,fill opacity=0.2]{};
\end{tikzpicture}}      
\end{document}

enter image description here

If you cannot install the recent version of tikzmark, you can do

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{fit}
% overleaf
\newcommand{\tikzmarknode}[3][]{\ifmmode%
\tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){$#3$};}%
\else%
\tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){#3};}%
\fi}
\usepackage{eso-pic}
\begin{document}
\[A = \det\begin{pmatrix} a_{11} & \cdots & \tikzmarknode{a1i}{a_{1i}} & \cdots & a_{1n}  \\ 
    \vdots & \ddots & \vdots & \reflectbox{$\ddots$} & \vdots \\
    \tikzmarknode{aj1}{a_{j1}} & \cdots & a_{ji} & \cdots & \tikzmarknode{ajn}{a_{jn}}  \\
    \vdots & \reflectbox{$\ddots$} & \ldots & \ddots & \vdots \\
    a_{n1} & \cdots &\tikzmarknode{ani}{a_{ni}} & \cdots & a_{nn}  \\
    \end{pmatrix}
\]
\AddToShipoutPictureBG*{\begin{tikzpicture}[overlay,remember picture]
\node[fit=(a1i) (ani),draw=red,fill=red,fill opacity=0.2]{};
\node[fit=(aj1) (ajn),draw=blue,fill=blue,fill opacity=0.2]{};
\end{tikzpicture}}      
\end{document}
  • exactly that, thanks. When I compiling I get this:! Undefined control sequence. l.13 ...\begin{array}{cccc} a_{11} & \tikzmarknode {a12}{a_{12}} & \ldots & a... – Giuliano Malatesta Apr 11 '19 at 10:27
  • @GiulianoMalatesta You need to update your TeX installation. \tikzmarknode has been added to the tikzmark library last year. –  Apr 11 '19 at 10:29
  • I've installed this texlive-tikzmark-8:svn44475-25.fc29.noarch. I can't install any newer version...btw in your code you inverted i with j, If I can't update the package I need to copy your image.. – Giuliano Malatesta Apr 11 '19 at 10:33
  • @GiulianoMalatesta Then do not load the tikzmark library and use \newcommand{\tikzmarknode}[3][]{\ifmmode% \tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){$#3$};}% \else% \tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){#3};}% \fi} instead. (I added an example as well.) –  Apr 11 '19 at 10:34
  • it produces only the matrix without the highlighting.. – Giuliano Malatesta Apr 11 '19 at 10:39
  • @GiulianoMalatesta You need to run it two or three times. –  Apr 11 '19 at 10:39
  • 1
    This solution doesn't seem to work inside a slide of a beamer presentation. – Māris Ozols Feb 02 '21 at 15:30
  • Likewise, this doesn't seem to work in a beamer presentation. – Charles Rezk Aug 27 '23 at 19:30