[Tex/LaTex] How to highlight a single element in a matrix

highlightingmatrices

I am trying to write out the LU decomposition of a matrix A. I am able to highlight the pivot column with elements below the pivot element except when I get to the last column. Does anyone know how I can highlight the last element, 2, in the same format? Or do you have suggestions of other ways that I could do this?

Here's what I'm trying to do.

 \documentclass[12pt,letterpaper]{report}


\usepackage{amsmath}
\usepackage{color}
\usepackage{arydshln}
\usepackage{tikz}
\usetikzlibrary{arrows,matrix,positioning}
\usetikzlibrary{fit}
\tikzset{%
 highlight/.style={rectangle,rounded corners,fill=blue!30,draw,
 fill opacity=0.2,thick,inner sep=0pt}
 }
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
 baseline=(#1.base)] \node (#1) {#2};}
 %
\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}



\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother

\begin{document}


\begin{align*}
A =
\left[ 
\begin{array} {*4{c}}
 \tikzmark{left}{2}& 1 & -1 & 4 \\ 
-4 & -3 & 6 & -3 \\ 
2 & -3 & 20 & 23 \\
 \tikzmark{right}{4} & 2 & 13 & 7
\end{array}
\right] 
\Highlight[first]
\sim 
\begin{matrix} 
\\ 
\mbox{$R_2+2R_1$} \\ 
\mbox{$R_3-R_1$} \\
\mbox{$R_4-2R_2$}
\end{matrix}
&\left[ 
2 & 1 & -1 & 4 \\ 
0 & \tikzmark{left}{-1} & 4 & 5 \\ 
0 & -4 & 21 & 19 \\
0 & \tikzmark{right}{0} & 15 & -1
\end{matrix}
\right]
\Highlight[first] \\
\sim
\begin{matrix} 
\\ 
\\ 
\mbox{$R_3-4R_2$} \\
\mbox{ }
\end{matrix}
&\left[ 
\begin{matrix} 
2 & 1 & -1 & 4 \\ 
0 & -1 & 4 & 5 \\ 
0 & 0 & \tikzmark{left}{5} & -1 \\
0 & 0 & \tikzmark{right}{15} & -1
\end{matrix}
\right]
\Highlight[first]\\
\sim
\begin{matrix} 
\\ 
\\ 
\\
\mbox{$R_4-3R_3$}
\end{matrix}
&\left[ 
\begin{matrix} 
2 & 1 & -1 & 4 \\ 
0 & -1 & 4 & 5 \\ 
0 & 0 & 5 & -1 \\
0 & 0 & 0 & 2
\end{matrix}
\right]
=U
\end{align*}



\end{document}

I need the last element, 2, to be highlighted just like the other pivot columns.

I am new user so I am not allowed to post an image but I hope someone can help with this.

Best Answer

update

\documentclass{article}
\usepackage{tikz,amsmath}

\begin{document}​  
\newcommand\hlight[1]{\tikz[overlay, remember picture,baseline=-\the\dimexpr\fontdimen22\textfont2\relax]\node[rectangle,fill=blue!50,rounded corners,fill opacity = 0.2,draw,thick,text opacity =1] {$#1$};} 

\begin{equation*}
  \begin{pmatrix}
           c &  -a    &   0    & \dots  & \dots  & \dots  &  0 \\
          -b &   \hlight{a}   &  -a    & \ddots &        &        & \vdots \\
           0 &  -b    &   c    & \ddots & \ddots &        & \vdots \\
      \vdots & \ddots & \ddots & \ddots & \ddots & \ddots & \vdots \\
      \vdots &        & \ddots & \ddots &   c    &  -a    &  0 \\
      \vdots &        &        & \ddots &  -b    &   c    & -a \\
           0 & \dots  & \dots  & \dots  &   0    &  -b    &  c
  \end{pmatrix}
\end{equation*}  
\end{document}​

enter image description here