TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a matrix shown below. I would like to have the whole row green rather than only the cells ... how can I do that?

\begin{equation}\label{eq:appendrow}
\newcommand\x{\times}
\newcommand\y{\colorbox{mygreen}{$1$}}
  \left(\begin{array}{cccc}
    \x  & \x  & \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    \y  & \y  & \y & \y \\
  \end{array}\right)
\end{equation}

and the output is:

enter image description here

share|improve this question
    
@user:66136: I have seen your question. The problem there is that you used twice the same identifiers (col 1 and col 2). As a result you get overlapping areas highlighted. – Claudio Fiandrino Mar 11 '15 at 10:03
up vote 19 down vote accepted

You can use \rowcolor, \columncolor, and \cellcolor from the colortbl package, loaded in my example through the xcolor package:

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

\newcommand\x{\times}
\newcommand\y{\cellcolor{green!10}}

\begin{document}

\begin{equation}\label{eq:appendrow}
  \left(\begin{array}{cccc}
    \rowcolor{red!20}
    \x  & \x  & \x & \x \\
    0   & \x  & \x & \x \\
   \rowcolor{blue!20}
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    \y a  &  b  & \y c &  d\\
  \end{array}\right)
\end{equation}

\begin{equation}
  \left(\begin{array}{>{\columncolor{olive!20}}cc>{\columncolor{yellow!20}}cc}
    \x  & \x  & \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    a  & b  & c & d \\
  \end{array}\right)
\end{equation}

\end{document}

enter image description here

share|improve this answer
1  
Muchisimas gracias! :) – Giovanni Azua Sep 1 '12 at 19:43

Another approach could be using the hf-tikz package.

Example:

\documentclass{article}
\usepackage{amsmath}

\newcommand\x{\times}

% requires version 0.3 of the package
\usepackage[customcolors]{hf-tikz}

\tikzset{style green/.style={
    set fill color=green!50!lime!60,
    set border color=white,
  },
  style cyan/.style={
    set fill color=cyan!90!blue!60,
    set border color=white,
  },
  style orange/.style={
    set fill color=orange!80!red!60,
    set border color=white,
  },
  hor/.style={
    above left offset={-0.15,0.31},
    below right offset={0.15,-0.125},
    #1
  },
  ver/.style={
    above left offset={-0.1,0.3},
    below right offset={0.15,-0.15},
    #1
  }
}

\begin{document}

\begin{equation}\label{eq:appendrow}
  \left(\begin{array}{cccc}
    \x  & \x  & \x & \x \\
    0   & \tikzmarkin[hor=style orange]{el} \x  & \x\tikzmarkend{el} & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    \tikzmarkin[hor=style green]{row} a  &  b  &  c &  d \tikzmarkend{row}\\
  \end{array}\right)
\end{equation}

\begin{equation}\label{eq:appendcol}
  \left(\begin{array}{cccc}
    \tikzmarkin[ver=style cyan]{col 1}\x  & \x  & \tikzmarkin[ver=style green]{col 2} \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    a \tikzmarkend{col 1}  &  b  &  c  \tikzmarkend{col 2} &  d \\
  \end{array}\right)
\end{equation}

\end{document}

Result:

enter image description here

share|improve this answer

Thank you for your answer. I would like to share that tip. First I will explain the problem, and after that, I will post the solution.

PROBLEM

If I do that:

    \begin{equation}\label{eq:appendcol}
  \left(\begin{array}{cccc}
    \tikzmarkin[ver=style red]{col 1}\x  & \x  & \tikzmarkin[ver=style red]{col 2} \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    a \tikzmarkend{col 1}  &  b  &  c  \tikzmarkend{col 2} &  d \\
  \end{array}\right)
\end{equation}

\begin{equation}\label{eq:appendcol}
  \left(\begin{array}{cccc}
    \tikzmarkin[ver=style red]{col 1}\x  & \x  & \tikzmarkin[ver=style red]{col 2} \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    a \tikzmarkend{col 1}  &  b  &  c  \tikzmarkend{col 2} &  d \\
  \end{array}\right)
\end{equation}

Vertical highlighting continues from first matrix to second, invading the space between them. The result:

Highlight invasion between 2 matrix using tkiz

SOLUTION

\begin{equation}\label{eq:appendcol}
  \left(\begin{array}{cccc}
    \tikzmarkin[ver=style red]{col 1}\x  & \x  & \tikzmarkin[ver=style red]{col 2} \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    a \tikzmarkend{col 1}  &  b  &  c  \tikzmarkend{col 2} &  d \\
  \end{array}\right)
\end{equation}

\begin{equation}\label{eq:appendcol-second}
  \left(\begin{array}{cccc}
    \tikzmarkin[ver=style red]{col 1-a}\x  & \x  & \tikzmarkin[ver=style red]{col 2-a} \x & \x \\
    0   & \x  & \x & \x \\
    0   & 0   & \x & \x \\
    0   & 0   & 0  & \x \\
    a \tikzmarkend{col 1-a}  &  b  &  c  \tikzmarkend{col 2-a} &  d \\
  \end{array}\right)
\end{equation}

And this is the final solution:

enter image description here

Special thanks to @percusse and @claudio-fiandrino that helped me to solve the problem on that post:

Problems with matix highlighting using tikz, 2 matrix

share|improve this answer
1  
This space is reserved for answers. If you have another question that is not answered here, please ask it by clicking the Ask Question button. Follow-up questions like this are more than welcome! You can link to this question to provide background if it helps motivate/clarify your question. – Paul Gessler Mar 10 '15 at 21:38
    
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. – mafp Mar 10 '15 at 22:02

I tried to use these useful advices, but I have to obtain colored vectors in a unique equation, with row×column products and so on. With the code (quasi-copypasted from your examples):

\begin{centered}
    $$E_{11} \simeq \braket{\mathbf{\Psi}_{11}|\hat{\mathcal{H}}'|\mathbf{\Psi}_{11}} =$$
    $$= \biggl\langle\frac{1}{\sqrt2}\psi_1(x_1)\psi_1(x_2)\bigl(\chi^+_1\chi^-_2 - \chi^+_2\chi^-_1\bigr)\Bigl|\hat{\mathcal{H}}'\Bigr|\frac{1}{\sqrt2}\psi_1(x_1)\psi_1(x_2)\bigl(\chi^+_1\chi^-_2 - \chi^+_2\chi^-_1\bigr)\biggr\rangle$$$$=\frac{1}{2}\bigint_{\mathbb{R}^2}{\psi_1^*(x_1)\psi_1^*(x_2)}\Bigl(
    \left(\begin{array}{cc}\tikzmarkin[hor=style orange]{el}1 & 0\tikzmarkend{el}\end{array}\right)\left(\begin{array}{cc}\tikzmarkin[hor=style green]{el}0 & 1\tikzmarkend{el}\end{array}\right)
    \left(\begin{array}{c}\tikzmarkin[hor=style orange]{el}1 \\ 0\tikzmarkend{el}\end{array}\right)
    \left(\begin{array}{c}\tikzmarkin[hor=style green]{el}0 \\ 1\tikzmarkend{el}\end{array}\right)$$
\end{centered}

I obtain this:

How I can solve this?

Thank you for your kindness, I know I shoold not ask for help in this space, but because of the affinity of the topic I think it can be useful also for future visitors.

share|improve this answer
1  
Welcome to TeX.SX! Your question won't be seen by many people here, so it would be best to repost it as a fresh question. Follow-up questions like this are more than welcome! Please use the "Ask Question" link for your new question; there you can link to this question to provide the background. – Thorsten Mar 26 at 9:43
    
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Jesse Mar 26 at 10:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.