Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a TikZ code that generates this:

enter image description here

using something along the lines of the following snippet. The full code corresponding to this snippet can be obtained from the answer to question tikz-two-blocks-matrix:

    \pgfmathparse{\y-\x<1?"draw":""}
    \node[\pgfmathresult](mynode-\x-\y) at (\y,-\x) {$\times$};

but I would like to instead have the following theme for those selected nodes. The code where this example originates from can be found in the answer to this other question tikz-marking-several-blocks-in-a-matrix and uses matrix array definition rather than painting everything using TikZ:

enter image description here

How can I do that using TikZ? it means to basically not have a border line but rather change the background of the square to a specific color ...

UPDATE: the following code and output is self-contained and shows the existing Tikz graph I have to which I would like to add the background color changes.

\documentclass{standalone}
    \usepackage{tikz}

    \usetikzlibrary{calc,fit,matrix,arrows,automata,positioning}
\begin{document}
\begin{tikzpicture}
[zeros/.style={},transform shape]
\foreach \y in {1,...,4}{
    \foreach \x in {1,...,5}{
    \ifnum\x>\numexpr\y+1
    \node[zeros] (mynode-\x-\y) at (\y,-\x) {0};
    \else
    \pgfmathparse{\y-\x<1?"draw":""}
    \node[\pgfmathresult](mynode-\x-\y) at (\y,-\x) {$\times$};
    \ifnum\x<5
    \ifnum\x<\y\draw[<-] (mynode-\x-\y) -- +(0,-0.7);\fi
    \ifnum\x=\y\draw[<-] (mynode-\x-\y) -- +(0,-0.7);\fi
    \ifnum\y<4\draw[<-] (mynode-\x-\y) -- +(0.7,-0.7);\fi
    \fi
    \fi
    }
}
\node[fit=(mynode-1-1)(mynode-5-4),draw,thick,red,label=90:{Conquer diagonal}]{};

\begin{scope}[xshift=5.2cm]
    \foreach \x[remember=\x as \lastx] in {1,...,5}{
        \node (myvecs1-\x) at (0,-\x) {$\times$};
        \node (myvecs2-\x) at (1,-\x) {$\times$};
        \node (myvecs3-\x) at (2,-\x) {$\times$};
        \node (myvecs4-\x) at (3,-\x) {$\times$};
        \node (myvecs5-\x) at (4,-\x) {$\times$};
        \node (myvecsn-\x) at (5,-\x) {$\times$};
        \ifnum\x>1
        \draw[->] (myvecs1-\x) -- (myvecs1-\lastx);
        \draw[->] (myvecs2-\x) -- (myvecs2-\lastx);
        \draw[->] (myvecs3-\x) -- (myvecs3-\lastx);
        \draw[->] (myvecs4-\x) -- (myvecs4-\lastx);
        \draw[->] (myvecs5-\x) -- (myvecs5-\lastx);
        \draw[->] (myvecsn-\x) -- (myvecsn-\lastx);
        \fi
        }
\node[fit=(myvecs1-1)(myvecsn-5),draw,thick,green,label=90:{Apply as deep as possible}] {};
\end{scope}
\end{tikzpicture}
\end{document}

The resulting output is:

enter image description here

share|improve this question
    
Could you post a small example document that provides the basic framework so people have something to play with? –  Jake Sep 4 '12 at 13:49
    
How about using some tikz from How to highlight a single element in a matrix? –  Werner Sep 4 '12 at 14:06
    
@Giovanni: None of the questions you linked to contain a full document, they're missing the \documentclass and the packages. I know it's not hard to guess these to create a compilable example, but it's not a very fun task for people who want to work on an answer. It's generally preferred to post full compilable minimal example documents instead of just snippets. –  Jake Sep 4 '12 at 14:10
    
@Werner there he uses pmatrix and uses TikZ to highlight something on pmatrix. Here the whole code is in TikZ so I have some node ... basically I would like this node to have a background color. –  Giovanni Azua Sep 4 '12 at 14:11
1  
OK full TikZ example added ... –  Giovanni Azua Sep 4 '12 at 17:58
show 4 more comments

1 Answer 1

up vote 4 down vote accepted

You could do it like this:

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}
[   zeros/.style={},
    transform shape
]
\foreach \y in {1,...,4}
{   \foreach \x in {1,...,5}{
  \ifnum\x>\numexpr\y+1
    \node[zeros] (mynode-\x-\y) at (\y,-\x) {0};
  \else
    \node(mynode-\x-\y) at (\y,-\x) {$\times$};
    \ifnum\x<5
        \ifnum\x=\y\fill[red,opacity=0.1] (mynode-\x-\y.south west) rectangle (mynode-\x-\y.north east);\fi
    \fi
    \ifnum\y=\numexpr\x-1\fill[opacity=0.1] (mynode-\x-\y.south west) rectangle (mynode-\x-\y.north east);\fi
  \fi
  }
}
\node[fit=(mynode-1-1)(mynode-5-4),draw,thick,red,label=90:{Conquer diagonal}]{};
\end{tikzpicture}

\end{document}

Result

enter image description here

share|improve this answer
add comment

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.