You could use TikZ, and
- the
fit
library for creating nodes fitting the desired area,
- a style for the highlighted node, so separated from the code and easy to change,
- the TikZ options
overlay
and remember picture
, so you can later refer to those nodes, for example for drawing arrows and annotations later.
To demonstrate why it's useful to have nodes for reference, I created an example, which shows transposing a matrix, highlights a submatrix both in the original matrix and the result, connected by an arrow and annotated:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw,
fill opacity=0.5,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) {};}
}
\begin{document}
\[
M = \left(\begin{array}{*5{c}}
\tikzmark{left}{1} & 2 & 3 & 4 & 5 \\
6 & 7 & 8 & 9 & 10 \\
11 & 12 & \tikzmark{right}{13} & 14 & 15 \\
16 & 17 & 18 & 19 & 20
\end{array}\right)
\Highlight[first]
\qquad
M^T = \left(\begin{array}{*5{c}}
\tikzmark{left}{1} & 6 & 11 & 16 \\
2 & 7 & 12 & 17 \\
3 & 8 & \tikzmark{right}{13} & 18 \\
4 & 9 & 14 & 19 \\
5 & 10 & 15 & 20
\end{array}\right)
\]
\Highlight[second]
%
\tikz[overlay,remember picture] {
\draw[->,thick,red,dashed] (first) -- (second) node [pos=0.66,above] {Transpose};
\node[above of=first] {$N$};
\node[above of=second] {$N^T$};
}
\end{document}
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}
Best Answer
A solution would be: