TikZ matrix, style for combination or rows and columnsIs there any efficient way to add cell identifier to...
What should tie a collection of short-stories together?
Why does Bach not break the rules here?
What options are left, if Britain cannot decide?
Why is the BSI not using powers of two?
A limit with limit zero everywhere must be zero somewhere
How to change two letters closest to a string and one letter immediately after a string using notepad++
How Could an Airship Be Repaired Mid-Flight
How do I hide Chekhov's Gun?
Life insurance that covers only simultaneous/dual deaths
What is this large pipe coming out of my roof?
Happy pi day, everyone!
Who is flying the vertibirds?
My adviser wants to be the first author
Are there other languages, besides English, where the indefinite (or definite) article varies based on sound?
The difference between「N分で」and「後N分で」
Instead of Universal Basic Income, why not Universal Basic NEEDS?
Employee lack of ownership
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
Why do passenger jet manufacturers design their planes with stall prevention systems?
Gravity magic - How does it work?
Existence of subset with given Hausdorff dimension
Is it possible to upcast ritual spells?
Do I need life insurance if I can cover my own funeral costs?
A sequence that has integer values for prime indexes only:
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?
documentclass{beamer}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
begin{tikzpicture}[row 2 column 3/.style=red]
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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?
documentclass{beamer}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
begin{tikzpicture}[row 2 column 3/.style=red]
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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?
documentclass{beamer}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
begin{tikzpicture}[row 2 column 3/.style=red]
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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?
documentclass{beamer}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
begin{tikzpicture}[row 2 column 3/.style=red]
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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.
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style={row 2 column #1/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
newcommand{rows}[2]{% #1 = rows, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{row r/.style={#2}}
}%
}
newcommand{cols}[2]{% #1 = columns, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{column r/.style={#2}}
}%
}
begin{tikzpicture}
cols{1,3}{blue}
rows{1,3}{red}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
newcommand{row}[2]{% #1 = row, #2 = style
tikzset{row #1/.style={#2}}}
newcommand{col}[2]{% #1 = column, #2 = style
tikzset{column #1/.style={#2}}}
begin{document}
begin{tikzpicture}
row{1}{red}
row{3}{red}
col{1}{blue}
col{3}{blue}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myblocks/.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}
}
}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style={row 2 column #1/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style={row 2 column #1/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style={row 2 column #1/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style={row 2 column #1/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myset/.style args = {(#1,#2)}{%
row #1 column #2/.style={nodes={text=red}}}}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
newcommand{rows}[2]{% #1 = rows, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{row r/.style={#2}}
}%
}
newcommand{cols}[2]{% #1 = columns, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{column r/.style={#2}}
}%
}
begin{tikzpicture}
cols{1,3}{blue}
rows{1,3}{red}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}

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:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
newcommand{rows}[2]{% #1 = rows, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{row r/.style={#2}}
}%
}
newcommand{cols}[2]{% #1 = columns, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{column r/.style={#2}}
}%
}
begin{tikzpicture}
cols{1,3}{blue}
rows{1,3}{red}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}

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:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
newcommand{rows}[2]{% #1 = rows, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{row r/.style={#2}}
}%
}
newcommand{cols}[2]{% #1 = columns, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{column r/.style={#2}}
}%
}
begin{tikzpicture}
cols{1,3}{blue}
rows{1,3}{red}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}

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:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
newcommand{rows}[2]{% #1 = rows, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{row r/.style={#2}}
}%
}
newcommand{cols}[2]{% #1 = columns, #2 = style
foreach r in {#1} {%
globaldefs=1relax
tikzset{column r/.style={#2}}
}%
}
begin{tikzpicture}
cols{1,3}{blue}
rows{1,3}{red}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
newcommand{row}[2]{% #1 = row, #2 = style
tikzset{row #1/.style={#2}}}
newcommand{col}[2]{% #1 = column, #2 = style
tikzset{column #1/.style={#2}}}
begin{document}
begin{tikzpicture}
row{1}{red}
row{3}{red}
col{1}{blue}
col{3}{blue}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
newcommand{row}[2]{% #1 = row, #2 = style
tikzset{row #1/.style={#2}}}
newcommand{col}[2]{% #1 = column, #2 = style
tikzset{column #1/.style={#2}}}
begin{document}
begin{tikzpicture}
row{1}{red}
row{3}{red}
col{1}{blue}
col{3}{blue}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
newcommand{row}[2]{% #1 = row, #2 = style
tikzset{row #1/.style={#2}}}
newcommand{col}[2]{% #1 = column, #2 = style
tikzset{column #1/.style={#2}}}
begin{document}
begin{tikzpicture}
row{1}{red}
row{3}{red}
col{1}{blue}
col{3}{blue}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
newcommand{row}[2]{% #1 = row, #2 = style
tikzset{row #1/.style={#2}}}
newcommand{col}[2]{% #1 = column, #2 = style
tikzset{column #1/.style={#2}}}
begin{document}
begin{tikzpicture}
row{1}{red}
row{3}{red}
col{1}{blue}
col{3}{blue}
matrix [matrix of nodes]
{
8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
};
end{tikzpicture}
end{document}
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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myblocks/.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}
}
}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myblocks/.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}
}
}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myblocks/.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}
}
}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

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.
documentclass{standalone}
usepackage{tikz}
usetikzlibrary{matrix}
begin{document}
tikzset{myblocks/.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}
}
}
begin{tikzpicture}[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 \
};
end{tikzpicture}
end{document}

edited 4 mins ago
answered 10 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