Math & ScienceHighlighting in matrices

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
salehin
Posts: 34
Joined: Wed Jun 10, 2009 1:29 am

Highlighting in matrices

Post by salehin »

Can you please let me know how to highlight (using any soft colour) the main diagonal of this square matrix.

Thank you for reading. :)

Code: Select all

\documentclass[a4paper]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amstext}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue}
\begin{document}
 
\begin{equation*}
    \left[
\begin{array}{cccc}
\sigma _{1}^{2} & \sigma _{12} & \cdots  & \sigma _{1k} \\
\sigma _{21} & \sigma _{2}^{2} & \cdots  & \sigma _{2k} \\
\vdots  & \vdots  & \ddots  & \vdots  \\
\sigma _{k1} & \sigma _{k2} & \cdots  & \sigma _{k}^{2}%
\end{array}
    \right] 
=\Omega
\end{equation*}

\end{document} 

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Highlighting in matrices

Post by gmedina »

Hi,

you could try using \cellcolor from the colortbl package, loaded via xcolor:

Code: Select all

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[table]{xcolor}

\begin{document}

\begin{equation*}
  \left[
  \begin{array}{cccc}
    \cellcolor{blue!20}\sigma _{1}^{2} & \sigma _{12} & \cdots  & \sigma _{1k} \\
    \sigma _{21} & \cellcolor{blue!20}\sigma _{2}^{2} & \cdots  & \sigma _{2k} \\
    \vdots  & \vdots  & \ddots  & \vdots  \\
    \sigma _{k1} & \sigma _{k2} & \cdots  & \cellcolor{blue!20}\sigma _{k}^{2}%
  \end{array}
  \right] 
  =\Omega
\end{equation*}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
salehin
Posts: 34
Joined: Wed Jun 10, 2009 1:29 am

Re: Highlighting in matrices

Post by salehin »

Thanks for your help, gmedina. It should do the job for me. :)

Regards

Saleh
tonyjnel
Posts: 11
Joined: Thu May 12, 2011 3:51 pm

Re: Highlighting in matrices

Post by tonyjnel »

That's really great gmedina, and I know i'm being nit-picky at this point, but is there a way that the highlighted cells can be highlighted by a triangle rather than the stair-step shape generated by this code. It may only make sense physically to do this with matrices that only have single character entries but can it be done?

Thanks,
Tony
Post Reply