TikZ matrix, style for combination or rows and columnsIs there any efficient way to add cell identifier to each cell in TikZ?How to have a specific style for empty cells in a tikz matrixIs it possible to add node labels to some matrix column or row when building it?TikZ Colorize a matrixThe simplest way to fill a matrix of nodes?Scaled TikZ matrix of nodesHow to overalap textbox in tikz?Why does a definition of macro containing multi raster column n/.style fail in tcbset of tcolorboxHow to annotate and shade a matrixIntersection of paths with constructed namesHow do I encircle a partial table in tikz?tikz matrix align/decorate cellpicturesNumerical conditional within tikz keys?how can I create keys such as “column … to …” for a TikZ matrixWhy do I get an extra white page before my TikZ picture?Table-like lines in tikz matrixStriking out matrix lines and columns: is Tikz the only way?How to draw a square and its diagonals with arrows?Limiting the scope of styles in TikZ matrix of nodes
How to deal with taxi scam when on vacation?
Are ETF trackers fundamentally better than individual stocks?
The difference between「N分で」and「後N分で」
Why doesn't using two cd commands in bash script execute the second command?
My adviser wants to be the first author
Brexit - No Deal Rejection
Professor being mistaken for a grad student
How do I hide Chekhov's Gun?
Use of undefined constant bloginfo
Have researchers managed to "reverse time"? If so, what does that mean for physics?
Life insurance that covers only simultaneous/dual deaths
Logical notation
My Graph Theory Students
Happy pi day, everyone!
What is this large pipe coming out of my roof?
Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is
Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible
Is a party consisting of only a bard, a cleric, and a warlock functional long-term?
AG Cluster db upgrade by vendor
Python if-else code style for reduced code
How to change two letters closest to a string and one letter immediately after a string using notepad++
What are substitutions for coconut in curry?
What options are left, if Britain cannot decide?
What is the rarity of this homebrew magic staff?
TikZ matrix, style for combination or rows and columns
Is there any efficient way to add cell identifier to each cell in TikZ?How to have a specific style for empty cells in a tikz matrixIs it possible to add node labels to some matrix column or row when building it?TikZ Colorize a matrixThe simplest way to fill a matrix of nodes?Scaled TikZ matrix of nodesHow to overalap textbox in tikz?Why does a definition of macro containing multi raster column n/.style fail in tcbset of tcolorboxHow to annotate and shade a matrixIntersection of paths with constructed namesHow do I encircle a partial table in tikz?tikz matrix align/decorate cellpicturesNumerical conditional within tikz keys?how can I create keys such as “column … to …” for a TikZ matrixWhy do I get an extra white page before my TikZ picture?Table-like lines in tikz matrixStriking out matrix lines and columns: is Tikz the only way?How to draw a square and its diagonals with arrows?Limiting the scope of styles in TikZ matrix of nodes
In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?
documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
tikz-pgf tikz-matrix
add a comment |
In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?
documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
tikz-pgf tikz-matrix
1
How simple? [row 1/.style=red, row 3/.style=red]
– John Kormylo
May 6 '14 at 13:32
@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?
– Sergio Parreiras
May 6 '14 at 15:57
You could create a new command, but it might get ugly.
– John Kormylo
May 6 '14 at 23:34
add a comment |
In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?
documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
tikz-pgf tikz-matrix
In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?
documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
tikz-pgf tikz-matrix
tikz-pgf tikz-matrix
edited May 7 '14 at 8:14
Sergio Parreiras
asked May 6 '14 at 12:31
Sergio ParreirasSergio Parreiras
6681825
6681825
1
How simple? [row 1/.style=red, row 3/.style=red]
– John Kormylo
May 6 '14 at 13:32
@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?
– Sergio Parreiras
May 6 '14 at 15:57
You could create a new command, but it might get ugly.
– John Kormylo
May 6 '14 at 23:34
add a comment |
1
How simple? [row 1/.style=red, row 3/.style=red]
– John Kormylo
May 6 '14 at 13:32
@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?
– Sergio Parreiras
May 6 '14 at 15:57
You could create a new command, but it might get ugly.
– John Kormylo
May 6 '14 at 23:34
1
1
How simple? [row 1/.style=red, row 3/.style=red]
– John Kormylo
May 6 '14 at 13:32
How simple? [row 1/.style=red, row 3/.style=red]
– John Kormylo
May 6 '14 at 13:32
@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?
– Sergio Parreiras
May 6 '14 at 15:57
@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?
– Sergio Parreiras
May 6 '14 at 15:57
You could create a new command, but it might get ugly.
– John Kormylo
May 6 '14 at 23:34
You could create a new command, but it might get ugly.
– John Kormylo
May 6 '14 at 23:34
add a comment |
5 Answers
5
active
oldest
votes
You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
begintikzpicture[myset/.list=1,3,5]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
1
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
add a comment |
More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style args = (#1,#2)%
row #1 column #2/.style=nodes=text=red
begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

add a comment |
This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
newcommandrows[2]% #1 = rows, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetrow r/.style=#2
%
newcommandcols[2]% #1 = columns, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetcolumn r/.style=#2
%
begintikzpicture
cols1,3blue
rows1,3red
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument

Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
add a comment |
Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
newcommandrow[2]% #1 = row, #2 = style
tikzsetrow #1/.style=#2
newcommandcol[2]% #1 = column, #2 = style
tikzsetcolumn #1/.style=#2
begindocument
begintikzpicture
row1red
row3red
col1blue
col3blue
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
add a comment |
I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
blockrows/.style=
block/.style=
row ##1 column ####1/.style=nodes=text=red
,
block/.list=#2,...,#4
,
blockrows/.list=#1,...,#3
begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f175616%2ftikz-matrix-style-for-combination-or-rows-and-columns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
begintikzpicture[myset/.list=1,3,5]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
1
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
add a comment |
You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
begintikzpicture[myset/.list=1,3,5]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
1
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
add a comment |
You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
begintikzpicture[myset/.list=1,3,5]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
begintikzpicture[myset/.list=1,3,5]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

answered May 7 '14 at 8:23
percussepercusse
138k14258496
138k14258496
list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
1
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
add a comment |
list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
1
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?
– Sergio Parreiras
May 7 '14 at 8:32
1
1
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
@SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.
– percusse
May 7 '14 at 8:33
add a comment |
More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style args = (#1,#2)%
row #1 column #2/.style=nodes=text=red
begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

add a comment |
More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style args = (#1,#2)%
row #1 column #2/.style=nodes=text=red
begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

add a comment |
More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style args = (#1,#2)%
row #1 column #2/.style=nodes=text=red
begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style args = (#1,#2)%
row #1 column #2/.style=nodes=text=red
begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

edited Apr 13 '17 at 12:35
Community♦
1
1
answered May 7 '14 at 9:09
cjorssencjorssen
5,646225104
5,646225104
add a comment |
add a comment |
This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
newcommandrows[2]% #1 = rows, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetrow r/.style=#2
%
newcommandcols[2]% #1 = columns, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetcolumn r/.style=#2
%
begintikzpicture
cols1,3blue
rows1,3red
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument

Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
add a comment |
This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
newcommandrows[2]% #1 = rows, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetrow r/.style=#2
%
newcommandcols[2]% #1 = columns, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetcolumn r/.style=#2
%
begintikzpicture
cols1,3blue
rows1,3red
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument

Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
add a comment |
This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
newcommandrows[2]% #1 = rows, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetrow r/.style=#2
%
newcommandcols[2]% #1 = columns, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetcolumn r/.style=#2
%
begintikzpicture
cols1,3blue
rows1,3red
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument

This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:
documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
newcommandrows[2]% #1 = rows, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetrow r/.style=#2
%
newcommandcols[2]% #1 = columns, #2 = style
foreach r in #1 %
globaldefs=1relax
tikzsetcolumn r/.style=#2
%
begintikzpicture
cols1,3blue
rows1,3red
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument

answered May 7 '14 at 8:36
JLDiazJLDiaz
50.1k4123186
50.1k4123186
Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
add a comment |
Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
Consider me considerably less fuzzy now.
– John Kormylo
May 7 '14 at 14:06
add a comment |
Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
newcommandrow[2]% #1 = row, #2 = style
tikzsetrow #1/.style=#2
newcommandcol[2]% #1 = column, #2 = style
tikzsetcolumn #1/.style=#2
begindocument
begintikzpicture
row1red
row3red
col1blue
col3blue
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
add a comment |
Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
newcommandrow[2]% #1 = row, #2 = style
tikzsetrow #1/.style=#2
newcommandcol[2]% #1 = column, #2 = style
tikzsetcolumn #1/.style=#2
begindocument
begintikzpicture
row1red
row3red
col1blue
col3blue
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
add a comment |
Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
newcommandrow[2]% #1 = row, #2 = style
tikzsetrow #1/.style=#2
newcommandcol[2]% #1 = column, #2 = style
tikzsetcolumn #1/.style=#2
begindocument
begintikzpicture
row1red
row3red
col1blue
col3blue
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
newcommandrow[2]% #1 = row, #2 = style
tikzsetrow #1/.style=#2
newcommandcol[2]% #1 = column, #2 = style
tikzsetcolumn #1/.style=#2
begindocument
begintikzpicture
row1red
row3red
col1blue
col3blue
matrix [matrix of nodes]
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument
answered May 7 '14 at 3:34
John KormyloJohn Kormylo
45.2k12570
45.2k12570
add a comment |
add a comment |
I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
blockrows/.style=
block/.style=
row ##1 column ####1/.style=nodes=text=red
,
block/.list=#2,...,#4
,
blockrows/.list=#1,...,#3
begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

add a comment |
I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
blockrows/.style=
block/.style=
row ##1 column ####1/.style=nodes=text=red
,
block/.list=#2,...,#4
,
blockrows/.list=#1,...,#3
begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

add a comment |
I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
blockrows/.style=
block/.style=
row ##1 column ####1/.style=nodes=text=red
,
block/.list=#2,...,#4
,
blockrows/.list=#1,...,#3
begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.
documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
blockrows/.style=
block/.style=
row ##1 column ####1/.style=nodes=text=red
,
block/.list=#2,...,#4
,
blockrows/.list=#1,...,#3
begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
matrix [matrix of nodes]
8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument

edited 8 mins ago
answered 14 mins ago
JPGJPG
1,392413
1,392413
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f175616%2ftikz-matrix-style-for-combination-or-rows-and-columns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
How simple? [row 1/.style=red, row 3/.style=red]
– John Kormylo
May 6 '14 at 13:32
@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?
– Sergio Parreiras
May 6 '14 at 15:57
You could create a new command, but it might get ugly.
– John Kormylo
May 6 '14 at 23:34