How to annotate and shade a matrixTikZ matrix, style for combination or rows and columnsHow to define the default vertical distance between nodes?TikZ: clipping and shade or fill drawingTikZ scaling graphic and adjust node position and keep font sizehow to annotate the following trapezoid picture?How can I annotate an image with arrow and text?TikZ/ERD: node (=Entity) label on the insideTable-like lines in tikz matrixHow to shade a parallelogram in TIKZannotate a tikz matrix-vector multiplication graphicHow to annotate matrix using tikz

SOQL: Populate a Literal List in WHERE IN Clause

Are ETF trackers fundamentally better than individual stocks?

How can you use ICE tables to solve multiple coupled equilibria?

Use void Apex method in Lightning Web Component

Python if-else code style for reduced code for rounding floats

Did Ender ever learn that he killed Stilson and/or Bonzo?

My adviser wants to be the first author

Why doesn't using two cd commands in bash script execute the second command?

How to terminate ping <dest> &

Stiffness of a cantilever beam

Hacking a Safe Lock after 3 tries

What options are left, if Britain cannot decide?

What's the meaning of “spike” in the context of “adrenaline spike”?

Define, (actually define) the "stability" and "energy" of a compound

Brexit - No Deal Rejection

Why do Australian milk farmers need to protest supermarkets' milk price?

Can a druid choose the size of its wild shape beast?

Min function accepting varying number of arguments in C++17

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

How to read the value of this capacitor?

Are there verbs that are neither telic, or atelic?

How to explain that I do not want to visit a country due to personal safety concern?

Use of undefined constant bloginfo

What do Xenomorphs eat in the Alien series?



How to annotate and shade a matrix


TikZ matrix, style for combination or rows and columnsHow to define the default vertical distance between nodes?TikZ: clipping and shade or fill drawingTikZ scaling graphic and adjust node position and keep font sizehow to annotate the following trapezoid picture?How can I annotate an image with arrow and text?TikZ/ERD: node (=Entity) label on the insideTable-like lines in tikz matrixHow to shade a parallelogram in TIKZannotate a tikz matrix-vector multiplication graphicHow to annotate matrix using tikz













2















I am trying to draw a dynamic programming matrix. My attempt so far is:



documentclass[]article
begindocument
begintabular
&&1&1&1&1&1&0&0&0&0&0&0&0&0&0&0\hlinehline
&0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15\hline
0&1&1&2&3&4&5&5&6&7&8&9&10&11&12&13&14\
0&2&2&2&3&4&5&5&5&6&7&8&9&10&11&12&13\
0&3&3&3&3&4&5&5&5&5&6&7&8&9&10&11&12\hline
1&4&3&3&3&3&4&5&6&6&6&7&8&9&10&11&12\
1&5&4&3&3&3&3&4&5&6&7&7&8&9&10&11&12\
1&6&5&4&3&3&3&4&5&6&7&8&8&9&10&11&12\
1&7&6&5&4&3&3&4&5&6&7&8&9&9&10&11&12\
1&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11&12\hline
0&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11\
0&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10\
0&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10\
0&12&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9\
endtabular
enddocument


I would now like to add two things:



  • Arrows between the numbers to show a shortest path from the top left to the bottom right.

  • I would like to shade some of the blocks in red (the ones where the symbols are different).

I tried to do this in tikz (with a different table) but it didn't go very well.



documentclassarticle
usepackagetikz
usetikzlibrarymatrix
usepackagepdflscape
begindocument
tikzset
table/.style=
matrix of nodes,
row sep=-pgflinewidth,
column sep=-pgflinewidth,
nodes=rectangle,text width=1.5em,align=center,
text depth=0.3125ex,
text height=0.625ex,
nodes in empty cells
,
row 1/.style=nodes=fill=green!10,text depth=0.4ex,text height=2ex,
row 6/.style=nodes=text depth=0.4ex,text height=2ex,
column 1/.style=nodes=fill=green!10,

beginlandscape
begintikzpicture
%begintabularc
matrix (mat) [table][fill=red!20];
foreach x in 2,6,9

draw
([xshift=-.125pgflinewidth,yshift=3]mat-x-1.south west) --
([xshift=-.125pgflinewidth,yshift=3]mat-x-27.south east);

beginscope[shorten >=7pt,shorten <= 7pt]
draw[->] (mat-2-2.center) -- (mat-2-3.center);
draw[->] (mat-2-3.center) -- (mat-2-4.center);
draw[->] (mat-2-4.center) -- (mat-3-5.center);
draw[->] (mat-3-5.center) -- (mat-4-6.center);
draw[->] (mat-4-6.center) -- (mat-5-7.center);
draw[->] (mat-5-7.center) -- (mat-6-8.center);
draw[->] (mat-6-8.center) -- (mat-7-9.center);
draw[->] (mat-7-9.center) -- (mat-8-10.center);
draw[->] (mat-8-10.center) -- (mat-9-11.center);
draw[->] (mat-9-11.center) -- (mat-10-12.center);

endscope

endtikzpicture
endlandscape
enddocument


This suffers from a few problems.



  • There is a strange space between two of the lines in the matrix.

  • The shading is shifted so it does not fill a block properly.

  • The arrows don't appear to be all lined up properly.

  • The LaTeX source is very wordy.

Any help much appreciated.










share|improve this question







New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • The «strange space between two of the lines in the matrix» is due to the special style command for row 6; what is the goal of this special style?

    – JPG
    6 hours ago











  • @JPG Oh that's just a bug and shouldn't be there! Thank you.

    – donald
    6 hours ago















2















I am trying to draw a dynamic programming matrix. My attempt so far is:



documentclass[]article
begindocument
begintabular
&&1&1&1&1&1&0&0&0&0&0&0&0&0&0&0\hlinehline
&0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15\hline
0&1&1&2&3&4&5&5&6&7&8&9&10&11&12&13&14\
0&2&2&2&3&4&5&5&5&6&7&8&9&10&11&12&13\
0&3&3&3&3&4&5&5&5&5&6&7&8&9&10&11&12\hline
1&4&3&3&3&3&4&5&6&6&6&7&8&9&10&11&12\
1&5&4&3&3&3&3&4&5&6&7&7&8&9&10&11&12\
1&6&5&4&3&3&3&4&5&6&7&8&8&9&10&11&12\
1&7&6&5&4&3&3&4&5&6&7&8&9&9&10&11&12\
1&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11&12\hline
0&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11\
0&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10\
0&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10\
0&12&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9\
endtabular
enddocument


I would now like to add two things:



  • Arrows between the numbers to show a shortest path from the top left to the bottom right.

  • I would like to shade some of the blocks in red (the ones where the symbols are different).

I tried to do this in tikz (with a different table) but it didn't go very well.



documentclassarticle
usepackagetikz
usetikzlibrarymatrix
usepackagepdflscape
begindocument
tikzset
table/.style=
matrix of nodes,
row sep=-pgflinewidth,
column sep=-pgflinewidth,
nodes=rectangle,text width=1.5em,align=center,
text depth=0.3125ex,
text height=0.625ex,
nodes in empty cells
,
row 1/.style=nodes=fill=green!10,text depth=0.4ex,text height=2ex,
row 6/.style=nodes=text depth=0.4ex,text height=2ex,
column 1/.style=nodes=fill=green!10,

beginlandscape
begintikzpicture
%begintabularc
matrix (mat) [table][fill=red!20];
foreach x in 2,6,9

draw
([xshift=-.125pgflinewidth,yshift=3]mat-x-1.south west) --
([xshift=-.125pgflinewidth,yshift=3]mat-x-27.south east);

beginscope[shorten >=7pt,shorten <= 7pt]
draw[->] (mat-2-2.center) -- (mat-2-3.center);
draw[->] (mat-2-3.center) -- (mat-2-4.center);
draw[->] (mat-2-4.center) -- (mat-3-5.center);
draw[->] (mat-3-5.center) -- (mat-4-6.center);
draw[->] (mat-4-6.center) -- (mat-5-7.center);
draw[->] (mat-5-7.center) -- (mat-6-8.center);
draw[->] (mat-6-8.center) -- (mat-7-9.center);
draw[->] (mat-7-9.center) -- (mat-8-10.center);
draw[->] (mat-8-10.center) -- (mat-9-11.center);
draw[->] (mat-9-11.center) -- (mat-10-12.center);

endscope

endtikzpicture
endlandscape
enddocument


This suffers from a few problems.



  • There is a strange space between two of the lines in the matrix.

  • The shading is shifted so it does not fill a block properly.

  • The arrows don't appear to be all lined up properly.

  • The LaTeX source is very wordy.

Any help much appreciated.










share|improve this question







New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • The «strange space between two of the lines in the matrix» is due to the special style command for row 6; what is the goal of this special style?

    – JPG
    6 hours ago











  • @JPG Oh that's just a bug and shouldn't be there! Thank you.

    – donald
    6 hours ago













2












2








2


1






I am trying to draw a dynamic programming matrix. My attempt so far is:



documentclass[]article
begindocument
begintabular
&&1&1&1&1&1&0&0&0&0&0&0&0&0&0&0\hlinehline
&0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15\hline
0&1&1&2&3&4&5&5&6&7&8&9&10&11&12&13&14\
0&2&2&2&3&4&5&5&5&6&7&8&9&10&11&12&13\
0&3&3&3&3&4&5&5&5&5&6&7&8&9&10&11&12\hline
1&4&3&3&3&3&4&5&6&6&6&7&8&9&10&11&12\
1&5&4&3&3&3&3&4&5&6&7&7&8&9&10&11&12\
1&6&5&4&3&3&3&4&5&6&7&8&8&9&10&11&12\
1&7&6&5&4&3&3&4&5&6&7&8&9&9&10&11&12\
1&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11&12\hline
0&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11\
0&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10\
0&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10\
0&12&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9\
endtabular
enddocument


I would now like to add two things:



  • Arrows between the numbers to show a shortest path from the top left to the bottom right.

  • I would like to shade some of the blocks in red (the ones where the symbols are different).

I tried to do this in tikz (with a different table) but it didn't go very well.



documentclassarticle
usepackagetikz
usetikzlibrarymatrix
usepackagepdflscape
begindocument
tikzset
table/.style=
matrix of nodes,
row sep=-pgflinewidth,
column sep=-pgflinewidth,
nodes=rectangle,text width=1.5em,align=center,
text depth=0.3125ex,
text height=0.625ex,
nodes in empty cells
,
row 1/.style=nodes=fill=green!10,text depth=0.4ex,text height=2ex,
row 6/.style=nodes=text depth=0.4ex,text height=2ex,
column 1/.style=nodes=fill=green!10,

beginlandscape
begintikzpicture
%begintabularc
matrix (mat) [table][fill=red!20];
foreach x in 2,6,9

draw
([xshift=-.125pgflinewidth,yshift=3]mat-x-1.south west) --
([xshift=-.125pgflinewidth,yshift=3]mat-x-27.south east);

beginscope[shorten >=7pt,shorten <= 7pt]
draw[->] (mat-2-2.center) -- (mat-2-3.center);
draw[->] (mat-2-3.center) -- (mat-2-4.center);
draw[->] (mat-2-4.center) -- (mat-3-5.center);
draw[->] (mat-3-5.center) -- (mat-4-6.center);
draw[->] (mat-4-6.center) -- (mat-5-7.center);
draw[->] (mat-5-7.center) -- (mat-6-8.center);
draw[->] (mat-6-8.center) -- (mat-7-9.center);
draw[->] (mat-7-9.center) -- (mat-8-10.center);
draw[->] (mat-8-10.center) -- (mat-9-11.center);
draw[->] (mat-9-11.center) -- (mat-10-12.center);

endscope

endtikzpicture
endlandscape
enddocument


This suffers from a few problems.



  • There is a strange space between two of the lines in the matrix.

  • The shading is shifted so it does not fill a block properly.

  • The arrows don't appear to be all lined up properly.

  • The LaTeX source is very wordy.

Any help much appreciated.










share|improve this question







New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am trying to draw a dynamic programming matrix. My attempt so far is:



documentclass[]article
begindocument
begintabular
&&1&1&1&1&1&0&0&0&0&0&0&0&0&0&0\hlinehline
&0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15\hline
0&1&1&2&3&4&5&5&6&7&8&9&10&11&12&13&14\
0&2&2&2&3&4&5&5&5&6&7&8&9&10&11&12&13\
0&3&3&3&3&4&5&5&5&5&6&7&8&9&10&11&12\hline
1&4&3&3&3&3&4&5&6&6&6&7&8&9&10&11&12\
1&5&4&3&3&3&3&4&5&6&7&7&8&9&10&11&12\
1&6&5&4&3&3&3&4&5&6&7&8&8&9&10&11&12\
1&7&6&5&4&3&3&4&5&6&7&8&9&9&10&11&12\
1&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11&12\hline
0&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10&11\
0&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10&10\
0&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9&10\
0&12&11&10&9&8&7&6&5&4&3&4&5&6&7&8&9\
endtabular
enddocument


I would now like to add two things:



  • Arrows between the numbers to show a shortest path from the top left to the bottom right.

  • I would like to shade some of the blocks in red (the ones where the symbols are different).

I tried to do this in tikz (with a different table) but it didn't go very well.



documentclassarticle
usepackagetikz
usetikzlibrarymatrix
usepackagepdflscape
begindocument
tikzset
table/.style=
matrix of nodes,
row sep=-pgflinewidth,
column sep=-pgflinewidth,
nodes=rectangle,text width=1.5em,align=center,
text depth=0.3125ex,
text height=0.625ex,
nodes in empty cells
,
row 1/.style=nodes=fill=green!10,text depth=0.4ex,text height=2ex,
row 6/.style=nodes=text depth=0.4ex,text height=2ex,
column 1/.style=nodes=fill=green!10,

beginlandscape
begintikzpicture
%begintabularc
matrix (mat) [table][fill=red!20];
foreach x in 2,6,9

draw
([xshift=-.125pgflinewidth,yshift=3]mat-x-1.south west) --
([xshift=-.125pgflinewidth,yshift=3]mat-x-27.south east);

beginscope[shorten >=7pt,shorten <= 7pt]
draw[->] (mat-2-2.center) -- (mat-2-3.center);
draw[->] (mat-2-3.center) -- (mat-2-4.center);
draw[->] (mat-2-4.center) -- (mat-3-5.center);
draw[->] (mat-3-5.center) -- (mat-4-6.center);
draw[->] (mat-4-6.center) -- (mat-5-7.center);
draw[->] (mat-5-7.center) -- (mat-6-8.center);
draw[->] (mat-6-8.center) -- (mat-7-9.center);
draw[->] (mat-7-9.center) -- (mat-8-10.center);
draw[->] (mat-8-10.center) -- (mat-9-11.center);
draw[->] (mat-9-11.center) -- (mat-10-12.center);

endscope

endtikzpicture
endlandscape
enddocument


This suffers from a few problems.



  • There is a strange space between two of the lines in the matrix.

  • The shading is shifted so it does not fill a block properly.

  • The arrows don't appear to be all lined up properly.

  • The LaTeX source is very wordy.

Any help much appreciated.







tikz-pgf






share|improve this question







New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 8 hours ago









donalddonald

111




111




New contributor




donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






donald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • The «strange space between two of the lines in the matrix» is due to the special style command for row 6; what is the goal of this special style?

    – JPG
    6 hours ago











  • @JPG Oh that's just a bug and shouldn't be there! Thank you.

    – donald
    6 hours ago

















  • The «strange space between two of the lines in the matrix» is due to the special style command for row 6; what is the goal of this special style?

    – JPG
    6 hours ago











  • @JPG Oh that's just a bug and shouldn't be there! Thank you.

    – donald
    6 hours ago
















The «strange space between two of the lines in the matrix» is due to the special style command for row 6; what is the goal of this special style?

– JPG
6 hours ago





The «strange space between two of the lines in the matrix» is due to the special style command for row 6; what is the goal of this special style?

– JPG
6 hours ago













@JPG Oh that's just a bug and shouldn't be there! Thank you.

– donald
6 hours ago





@JPG Oh that's just a bug and shouldn't be there! Thank you.

– donald
6 hours ago










1 Answer
1






active

oldest

votes


















2














Here are come correction:



  • removing row 6 style

  • removing text depth and setting text height to 1.1ex in order to avoid shifts between the fill and the content of the cells


  • shading areas with a 20% opacity rectangle above the matrix instead of filling each cell.



    documentclassstandalone
    usepackagetikz
    usetikzlibrarymatrix
    begindocument
    tikzset
    table/.style=
    matrix of nodes,
    row sep=-pgflinewidth,
    column sep=-pgflinewidth,
    nodes=rectangle,text width=1.5em,align=center,
    text height=1.1ex,
    nodes in empty cells,
    ,
    row 1/.style=nodes=fill=green!10,
    column 1/.style=nodes=fill=green!10


    begintikzpicture
    matrix (mat) [table]
    &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
    &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
    1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
    1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
    1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
    1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
    0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
    0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
    0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
    1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
    ;
    fill[red,opacity=0.2] (mat-3-3.north west) rectangle (mat-6-12.south east);
    fill[red,opacity=0.2] (mat-7-13.north west) rectangle (mat-9-18.south east);
    fill[red,opacity=0.2] (mat-3-19.north west) rectangle (mat-6-27.south east);
    fill[red,opacity=0.2] (mat-10-3.north west) rectangle (mat-10-12.south east);
    fill[red,opacity=0.2] (mat-10-19.north west) rectangle (mat-10-27.south east);
    foreach x in 2,6,9

    draw
    ([xshift=-.125pgflinewidth]mat-x-1.south west) --
    ([xshift=-.125pgflinewidth]mat-x-27.south east);

    beginscope[shorten >=7pt,shorten <= 7pt]
    draw[->] (mat-2-2.center) -- (mat-2-3.center);
    draw[->] (mat-2-3.center) -- (mat-2-4.center);
    draw[->] (mat-2-4.center) -- (mat-3-5.center);
    draw[->] (mat-3-5.center) -- (mat-4-6.center);
    draw[->] (mat-4-6.center) -- (mat-5-7.center);
    draw[->] (mat-5-7.center) -- (mat-6-8.center);
    draw[->] (mat-6-8.center) -- (mat-7-9.center);
    draw[->] (mat-7-9.center) -- (mat-8-10.center);
    draw[->] (mat-8-10.center) -- (mat-9-11.center);
    draw[->] (mat-9-11.center) -- (mat-10-12.center);

    endscope

    endtikzpicture
    enddocument


enter image description here



Edit



Coloring blocks of a matrix by filling a 20% opaque rectangle above it was a solution that did not satisfy me. I wanted to block-assign styles to cell, but tikz doesn't have options for that. After working from the answers to this question, I managed to do it: the filinred option defines styles for a block of cells through 2 loops (defined with /.list), and then the list of blocks is defined at the beginning of the matrix with format (top,left to bottom,right):



documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzset
table/.style=
matrix of nodes,
row sep=-pgflinewidth,
column sep=-pgflinewidth,
nodes=rectangle,text width=1.5em,align=center,
text height=1.1ex,
nodes in empty cells,
,
row 1/.style=nodes=fill=green!10,
column 1/.style=nodes=fill=green!10,
fillinred/.style args = (#1,#2 to #3,#4)
blockrows/.style=
block/.style=
row ##1 column ####1/.style=nodes=fill=red!20
,
block/.list=#2,...,#4
,
blockrows/.list=#1,...,#3



begintikzpicture
matrix (mat) [table,fillinred/.list=(3,3 to 6,12),(10,3 to 10,12),(7,13 to 9,18),(3,19 to 6,27),(10,19 to 10,27)]
&&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
&0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
;
foreach x in 2,6,9

draw
([xshift=-.125pgflinewidth]mat-x-1.south west) --
([xshift=-.125pgflinewidth]mat-x-27.south east);

beginscope[shorten >=7pt,shorten <= 7pt]
draw[->] (mat-2-2.center) -- (mat-2-3.center);
draw[->] (mat-2-3.center) -- (mat-2-4.center);
draw[->] (mat-2-4.center) -- (mat-3-5.center);
draw[->] (mat-3-5.center) -- (mat-4-6.center);
draw[->] (mat-4-6.center) -- (mat-5-7.center);
draw[->] (mat-5-7.center) -- (mat-6-8.center);
draw[->] (mat-6-8.center) -- (mat-7-9.center);
draw[->] (mat-7-9.center) -- (mat-8-10.center);
draw[->] (mat-8-10.center) -- (mat-9-11.center);
draw[->] (mat-9-11.center) -- (mat-10-12.center);
endscope

endtikzpicture
enddocument





share|improve this answer
























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    donald is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f479655%2fhow-to-annotate-and-shade-a-matrix%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Here are come correction:



    • removing row 6 style

    • removing text depth and setting text height to 1.1ex in order to avoid shifts between the fill and the content of the cells


    • shading areas with a 20% opacity rectangle above the matrix instead of filling each cell.



      documentclassstandalone
      usepackagetikz
      usetikzlibrarymatrix
      begindocument
      tikzset
      table/.style=
      matrix of nodes,
      row sep=-pgflinewidth,
      column sep=-pgflinewidth,
      nodes=rectangle,text width=1.5em,align=center,
      text height=1.1ex,
      nodes in empty cells,
      ,
      row 1/.style=nodes=fill=green!10,
      column 1/.style=nodes=fill=green!10


      begintikzpicture
      matrix (mat) [table]
      &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
      &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
      1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
      1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
      1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
      1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
      0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
      0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
      0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
      1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
      ;
      fill[red,opacity=0.2] (mat-3-3.north west) rectangle (mat-6-12.south east);
      fill[red,opacity=0.2] (mat-7-13.north west) rectangle (mat-9-18.south east);
      fill[red,opacity=0.2] (mat-3-19.north west) rectangle (mat-6-27.south east);
      fill[red,opacity=0.2] (mat-10-3.north west) rectangle (mat-10-12.south east);
      fill[red,opacity=0.2] (mat-10-19.north west) rectangle (mat-10-27.south east);
      foreach x in 2,6,9

      draw
      ([xshift=-.125pgflinewidth]mat-x-1.south west) --
      ([xshift=-.125pgflinewidth]mat-x-27.south east);

      beginscope[shorten >=7pt,shorten <= 7pt]
      draw[->] (mat-2-2.center) -- (mat-2-3.center);
      draw[->] (mat-2-3.center) -- (mat-2-4.center);
      draw[->] (mat-2-4.center) -- (mat-3-5.center);
      draw[->] (mat-3-5.center) -- (mat-4-6.center);
      draw[->] (mat-4-6.center) -- (mat-5-7.center);
      draw[->] (mat-5-7.center) -- (mat-6-8.center);
      draw[->] (mat-6-8.center) -- (mat-7-9.center);
      draw[->] (mat-7-9.center) -- (mat-8-10.center);
      draw[->] (mat-8-10.center) -- (mat-9-11.center);
      draw[->] (mat-9-11.center) -- (mat-10-12.center);

      endscope

      endtikzpicture
      enddocument


    enter image description here



    Edit



    Coloring blocks of a matrix by filling a 20% opaque rectangle above it was a solution that did not satisfy me. I wanted to block-assign styles to cell, but tikz doesn't have options for that. After working from the answers to this question, I managed to do it: the filinred option defines styles for a block of cells through 2 loops (defined with /.list), and then the list of blocks is defined at the beginning of the matrix with format (top,left to bottom,right):



    documentclassstandalone
    usepackagetikz
    usetikzlibrarymatrix
    begindocument
    tikzset
    table/.style=
    matrix of nodes,
    row sep=-pgflinewidth,
    column sep=-pgflinewidth,
    nodes=rectangle,text width=1.5em,align=center,
    text height=1.1ex,
    nodes in empty cells,
    ,
    row 1/.style=nodes=fill=green!10,
    column 1/.style=nodes=fill=green!10,
    fillinred/.style args = (#1,#2 to #3,#4)
    blockrows/.style=
    block/.style=
    row ##1 column ####1/.style=nodes=fill=red!20
    ,
    block/.list=#2,...,#4
    ,
    blockrows/.list=#1,...,#3



    begintikzpicture
    matrix (mat) [table,fillinred/.list=(3,3 to 6,12),(10,3 to 10,12),(7,13 to 9,18),(3,19 to 6,27),(10,19 to 10,27)]
    &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
    &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
    1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
    1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
    1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
    1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
    0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
    0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
    0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
    1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
    ;
    foreach x in 2,6,9

    draw
    ([xshift=-.125pgflinewidth]mat-x-1.south west) --
    ([xshift=-.125pgflinewidth]mat-x-27.south east);

    beginscope[shorten >=7pt,shorten <= 7pt]
    draw[->] (mat-2-2.center) -- (mat-2-3.center);
    draw[->] (mat-2-3.center) -- (mat-2-4.center);
    draw[->] (mat-2-4.center) -- (mat-3-5.center);
    draw[->] (mat-3-5.center) -- (mat-4-6.center);
    draw[->] (mat-4-6.center) -- (mat-5-7.center);
    draw[->] (mat-5-7.center) -- (mat-6-8.center);
    draw[->] (mat-6-8.center) -- (mat-7-9.center);
    draw[->] (mat-7-9.center) -- (mat-8-10.center);
    draw[->] (mat-8-10.center) -- (mat-9-11.center);
    draw[->] (mat-9-11.center) -- (mat-10-12.center);
    endscope

    endtikzpicture
    enddocument





    share|improve this answer





























      2














      Here are come correction:



      • removing row 6 style

      • removing text depth and setting text height to 1.1ex in order to avoid shifts between the fill and the content of the cells


      • shading areas with a 20% opacity rectangle above the matrix instead of filling each cell.



        documentclassstandalone
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzset
        table/.style=
        matrix of nodes,
        row sep=-pgflinewidth,
        column sep=-pgflinewidth,
        nodes=rectangle,text width=1.5em,align=center,
        text height=1.1ex,
        nodes in empty cells,
        ,
        row 1/.style=nodes=fill=green!10,
        column 1/.style=nodes=fill=green!10


        begintikzpicture
        matrix (mat) [table]
        &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
        &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
        1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
        1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
        1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
        1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
        0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
        0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
        0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
        1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
        ;
        fill[red,opacity=0.2] (mat-3-3.north west) rectangle (mat-6-12.south east);
        fill[red,opacity=0.2] (mat-7-13.north west) rectangle (mat-9-18.south east);
        fill[red,opacity=0.2] (mat-3-19.north west) rectangle (mat-6-27.south east);
        fill[red,opacity=0.2] (mat-10-3.north west) rectangle (mat-10-12.south east);
        fill[red,opacity=0.2] (mat-10-19.north west) rectangle (mat-10-27.south east);
        foreach x in 2,6,9

        draw
        ([xshift=-.125pgflinewidth]mat-x-1.south west) --
        ([xshift=-.125pgflinewidth]mat-x-27.south east);

        beginscope[shorten >=7pt,shorten <= 7pt]
        draw[->] (mat-2-2.center) -- (mat-2-3.center);
        draw[->] (mat-2-3.center) -- (mat-2-4.center);
        draw[->] (mat-2-4.center) -- (mat-3-5.center);
        draw[->] (mat-3-5.center) -- (mat-4-6.center);
        draw[->] (mat-4-6.center) -- (mat-5-7.center);
        draw[->] (mat-5-7.center) -- (mat-6-8.center);
        draw[->] (mat-6-8.center) -- (mat-7-9.center);
        draw[->] (mat-7-9.center) -- (mat-8-10.center);
        draw[->] (mat-8-10.center) -- (mat-9-11.center);
        draw[->] (mat-9-11.center) -- (mat-10-12.center);

        endscope

        endtikzpicture
        enddocument


      enter image description here



      Edit



      Coloring blocks of a matrix by filling a 20% opaque rectangle above it was a solution that did not satisfy me. I wanted to block-assign styles to cell, but tikz doesn't have options for that. After working from the answers to this question, I managed to do it: the filinred option defines styles for a block of cells through 2 loops (defined with /.list), and then the list of blocks is defined at the beginning of the matrix with format (top,left to bottom,right):



      documentclassstandalone
      usepackagetikz
      usetikzlibrarymatrix
      begindocument
      tikzset
      table/.style=
      matrix of nodes,
      row sep=-pgflinewidth,
      column sep=-pgflinewidth,
      nodes=rectangle,text width=1.5em,align=center,
      text height=1.1ex,
      nodes in empty cells,
      ,
      row 1/.style=nodes=fill=green!10,
      column 1/.style=nodes=fill=green!10,
      fillinred/.style args = (#1,#2 to #3,#4)
      blockrows/.style=
      block/.style=
      row ##1 column ####1/.style=nodes=fill=red!20
      ,
      block/.list=#2,...,#4
      ,
      blockrows/.list=#1,...,#3



      begintikzpicture
      matrix (mat) [table,fillinred/.list=(3,3 to 6,12),(10,3 to 10,12),(7,13 to 9,18),(3,19 to 6,27),(10,19 to 10,27)]
      &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
      &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
      1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
      1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
      1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
      1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
      0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
      0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
      0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
      1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
      ;
      foreach x in 2,6,9

      draw
      ([xshift=-.125pgflinewidth]mat-x-1.south west) --
      ([xshift=-.125pgflinewidth]mat-x-27.south east);

      beginscope[shorten >=7pt,shorten <= 7pt]
      draw[->] (mat-2-2.center) -- (mat-2-3.center);
      draw[->] (mat-2-3.center) -- (mat-2-4.center);
      draw[->] (mat-2-4.center) -- (mat-3-5.center);
      draw[->] (mat-3-5.center) -- (mat-4-6.center);
      draw[->] (mat-4-6.center) -- (mat-5-7.center);
      draw[->] (mat-5-7.center) -- (mat-6-8.center);
      draw[->] (mat-6-8.center) -- (mat-7-9.center);
      draw[->] (mat-7-9.center) -- (mat-8-10.center);
      draw[->] (mat-8-10.center) -- (mat-9-11.center);
      draw[->] (mat-9-11.center) -- (mat-10-12.center);
      endscope

      endtikzpicture
      enddocument





      share|improve this answer



























        2












        2








        2







        Here are come correction:



        • removing row 6 style

        • removing text depth and setting text height to 1.1ex in order to avoid shifts between the fill and the content of the cells


        • shading areas with a 20% opacity rectangle above the matrix instead of filling each cell.



          documentclassstandalone
          usepackagetikz
          usetikzlibrarymatrix
          begindocument
          tikzset
          table/.style=
          matrix of nodes,
          row sep=-pgflinewidth,
          column sep=-pgflinewidth,
          nodes=rectangle,text width=1.5em,align=center,
          text height=1.1ex,
          nodes in empty cells,
          ,
          row 1/.style=nodes=fill=green!10,
          column 1/.style=nodes=fill=green!10


          begintikzpicture
          matrix (mat) [table]
          &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
          &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
          1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
          1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
          1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
          1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
          0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
          0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
          0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
          1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
          ;
          fill[red,opacity=0.2] (mat-3-3.north west) rectangle (mat-6-12.south east);
          fill[red,opacity=0.2] (mat-7-13.north west) rectangle (mat-9-18.south east);
          fill[red,opacity=0.2] (mat-3-19.north west) rectangle (mat-6-27.south east);
          fill[red,opacity=0.2] (mat-10-3.north west) rectangle (mat-10-12.south east);
          fill[red,opacity=0.2] (mat-10-19.north west) rectangle (mat-10-27.south east);
          foreach x in 2,6,9

          draw
          ([xshift=-.125pgflinewidth]mat-x-1.south west) --
          ([xshift=-.125pgflinewidth]mat-x-27.south east);

          beginscope[shorten >=7pt,shorten <= 7pt]
          draw[->] (mat-2-2.center) -- (mat-2-3.center);
          draw[->] (mat-2-3.center) -- (mat-2-4.center);
          draw[->] (mat-2-4.center) -- (mat-3-5.center);
          draw[->] (mat-3-5.center) -- (mat-4-6.center);
          draw[->] (mat-4-6.center) -- (mat-5-7.center);
          draw[->] (mat-5-7.center) -- (mat-6-8.center);
          draw[->] (mat-6-8.center) -- (mat-7-9.center);
          draw[->] (mat-7-9.center) -- (mat-8-10.center);
          draw[->] (mat-8-10.center) -- (mat-9-11.center);
          draw[->] (mat-9-11.center) -- (mat-10-12.center);

          endscope

          endtikzpicture
          enddocument


        enter image description here



        Edit



        Coloring blocks of a matrix by filling a 20% opaque rectangle above it was a solution that did not satisfy me. I wanted to block-assign styles to cell, but tikz doesn't have options for that. After working from the answers to this question, I managed to do it: the filinred option defines styles for a block of cells through 2 loops (defined with /.list), and then the list of blocks is defined at the beginning of the matrix with format (top,left to bottom,right):



        documentclassstandalone
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzset
        table/.style=
        matrix of nodes,
        row sep=-pgflinewidth,
        column sep=-pgflinewidth,
        nodes=rectangle,text width=1.5em,align=center,
        text height=1.1ex,
        nodes in empty cells,
        ,
        row 1/.style=nodes=fill=green!10,
        column 1/.style=nodes=fill=green!10,
        fillinred/.style args = (#1,#2 to #3,#4)
        blockrows/.style=
        block/.style=
        row ##1 column ####1/.style=nodes=fill=red!20
        ,
        block/.list=#2,...,#4
        ,
        blockrows/.list=#1,...,#3



        begintikzpicture
        matrix (mat) [table,fillinred/.list=(3,3 to 6,12),(10,3 to 10,12),(7,13 to 9,18),(3,19 to 6,27),(10,19 to 10,27)]
        &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
        &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
        1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
        1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
        1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
        1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
        0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
        0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
        0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
        1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
        ;
        foreach x in 2,6,9

        draw
        ([xshift=-.125pgflinewidth]mat-x-1.south west) --
        ([xshift=-.125pgflinewidth]mat-x-27.south east);

        beginscope[shorten >=7pt,shorten <= 7pt]
        draw[->] (mat-2-2.center) -- (mat-2-3.center);
        draw[->] (mat-2-3.center) -- (mat-2-4.center);
        draw[->] (mat-2-4.center) -- (mat-3-5.center);
        draw[->] (mat-3-5.center) -- (mat-4-6.center);
        draw[->] (mat-4-6.center) -- (mat-5-7.center);
        draw[->] (mat-5-7.center) -- (mat-6-8.center);
        draw[->] (mat-6-8.center) -- (mat-7-9.center);
        draw[->] (mat-7-9.center) -- (mat-8-10.center);
        draw[->] (mat-8-10.center) -- (mat-9-11.center);
        draw[->] (mat-9-11.center) -- (mat-10-12.center);
        endscope

        endtikzpicture
        enddocument





        share|improve this answer















        Here are come correction:



        • removing row 6 style

        • removing text depth and setting text height to 1.1ex in order to avoid shifts between the fill and the content of the cells


        • shading areas with a 20% opacity rectangle above the matrix instead of filling each cell.



          documentclassstandalone
          usepackagetikz
          usetikzlibrarymatrix
          begindocument
          tikzset
          table/.style=
          matrix of nodes,
          row sep=-pgflinewidth,
          column sep=-pgflinewidth,
          nodes=rectangle,text width=1.5em,align=center,
          text height=1.1ex,
          nodes in empty cells,
          ,
          row 1/.style=nodes=fill=green!10,
          column 1/.style=nodes=fill=green!10


          begintikzpicture
          matrix (mat) [table]
          &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
          &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
          1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
          1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
          1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
          1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
          0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
          0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
          0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
          1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
          ;
          fill[red,opacity=0.2] (mat-3-3.north west) rectangle (mat-6-12.south east);
          fill[red,opacity=0.2] (mat-7-13.north west) rectangle (mat-9-18.south east);
          fill[red,opacity=0.2] (mat-3-19.north west) rectangle (mat-6-27.south east);
          fill[red,opacity=0.2] (mat-10-3.north west) rectangle (mat-10-12.south east);
          fill[red,opacity=0.2] (mat-10-19.north west) rectangle (mat-10-27.south east);
          foreach x in 2,6,9

          draw
          ([xshift=-.125pgflinewidth]mat-x-1.south west) --
          ([xshift=-.125pgflinewidth]mat-x-27.south east);

          beginscope[shorten >=7pt,shorten <= 7pt]
          draw[->] (mat-2-2.center) -- (mat-2-3.center);
          draw[->] (mat-2-3.center) -- (mat-2-4.center);
          draw[->] (mat-2-4.center) -- (mat-3-5.center);
          draw[->] (mat-3-5.center) -- (mat-4-6.center);
          draw[->] (mat-4-6.center) -- (mat-5-7.center);
          draw[->] (mat-5-7.center) -- (mat-6-8.center);
          draw[->] (mat-6-8.center) -- (mat-7-9.center);
          draw[->] (mat-7-9.center) -- (mat-8-10.center);
          draw[->] (mat-8-10.center) -- (mat-9-11.center);
          draw[->] (mat-9-11.center) -- (mat-10-12.center);

          endscope

          endtikzpicture
          enddocument


        enter image description here



        Edit



        Coloring blocks of a matrix by filling a 20% opaque rectangle above it was a solution that did not satisfy me. I wanted to block-assign styles to cell, but tikz doesn't have options for that. After working from the answers to this question, I managed to do it: the filinred option defines styles for a block of cells through 2 loops (defined with /.list), and then the list of blocks is defined at the beginning of the matrix with format (top,left to bottom,right):



        documentclassstandalone
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzset
        table/.style=
        matrix of nodes,
        row sep=-pgflinewidth,
        column sep=-pgflinewidth,
        nodes=rectangle,text width=1.5em,align=center,
        text height=1.1ex,
        nodes in empty cells,
        ,
        row 1/.style=nodes=fill=green!10,
        column 1/.style=nodes=fill=green!10,
        fillinred/.style args = (#1,#2 to #3,#4)
        blockrows/.style=
        block/.style=
        row ##1 column ####1/.style=nodes=fill=red!20
        ,
        block/.list=#2,...,#4
        ,
        blockrows/.list=#1,...,#3



        begintikzpicture
        matrix (mat) [table,fillinred/.list=(3,3 to 6,12),(10,3 to 10,12),(7,13 to 9,18),(3,19 to 6,27),(10,19 to 10,27)]
        &&0&0&0&0&0&0&0&0&0&0&1&1&1&1&1&1&0&0&0&0&0&0&0&0&0\
        &0&1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24&25\
        1&1&1&2&3&4&5&6&7&8&9&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23&24\
        1&2&2&2&3&4&5&6&7&8&9&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22&23\
        1&3&3&3&3&4&5&6&7&8&9&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21&22\
        1&4&4&4&4&4&5&6&7&8&9&10&10&10&10&10&11&12&13&14&15&16&17&18&19&20&21\
        0&5&4&4&4&4&4&5&6&7&8&9&10&11&11&11&11&12&12&13&14&15&16&17&18&19&20\
        0&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&12&12&12&12&13&14&15&16&17&18&19\
        0&7&6&5&4&4&4&4&4&5&6&7&8&9&10&11&12&13&12&12&12&13&14&15&16&17&18\
        1&8&7&6&5&5&5&5&5&5&6&7&7&8&9&10&11&12&13&13&13&13&14&15&16&17&18\
        ;
        foreach x in 2,6,9

        draw
        ([xshift=-.125pgflinewidth]mat-x-1.south west) --
        ([xshift=-.125pgflinewidth]mat-x-27.south east);

        beginscope[shorten >=7pt,shorten <= 7pt]
        draw[->] (mat-2-2.center) -- (mat-2-3.center);
        draw[->] (mat-2-3.center) -- (mat-2-4.center);
        draw[->] (mat-2-4.center) -- (mat-3-5.center);
        draw[->] (mat-3-5.center) -- (mat-4-6.center);
        draw[->] (mat-4-6.center) -- (mat-5-7.center);
        draw[->] (mat-5-7.center) -- (mat-6-8.center);
        draw[->] (mat-6-8.center) -- (mat-7-9.center);
        draw[->] (mat-7-9.center) -- (mat-8-10.center);
        draw[->] (mat-8-10.center) -- (mat-9-11.center);
        draw[->] (mat-9-11.center) -- (mat-10-12.center);
        endscope

        endtikzpicture
        enddocument






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 hours ago

























        answered 4 hours ago









        JPGJPG

        1,402413




        1,402413




















            donald is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            donald is a new contributor. Be nice, and check out our Code of Conduct.












            donald is a new contributor. Be nice, and check out our Code of Conduct.











            donald is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f479655%2fhow-to-annotate-and-shade-a-matrix%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How should I use the fbox command correctly to avoid producing a Bad Box message?How to put a long piece of text in a box?How to specify height and width of fboxIs there an arrayrulecolor-like command to change the rule color of fbox?What is the command to highlight bad boxes in pdf?Why does fbox sometimes place the box *over* the graphic image?how to put the text in the boxHow to create command for a box where text inside the box can automatically adjust?how can I make an fbox like command with certain color, shape and width of border?how to use fbox in align modeFbox increase the spacing between the box and it content (inner margin)how to change the box height of an equationWhat is the use of the hbox in a newcommand command?

            152 Atala Notae | Nexus externi | Tabula navigationis"Discovery Circumstances: Numbered Minor Planets"2000152Small-Body Database

            Doxepinum Nexus interni Notae | Tabula navigationis3158DB01142WHOa682390"Structural Analysis of the Histamine H1 Receptor""Transdermal and Topical Drug Administration in the Treatment of Pain""Antidepressants as antipruritic agents: A review"