Is there any efficient way to add cell identifier to each cell in TikZ?
I made a grid with TikZ. I would like to add the cell number in each cell (in the middle of each cell),
I used this command
draw (-4,2.5) node[below] {$Z_1$};
But this solution is time consuming. Is there any efficient way to add cell identifier to each cell?
documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
draw (-4,2.5) node[below] {$Z_1$};
end{tikzpicture}
end{document}
This what I want to draw:

tikz-pgf formatting tikz-styles tikz-arrows
add a comment |
I made a grid with TikZ. I would like to add the cell number in each cell (in the middle of each cell),
I used this command
draw (-4,2.5) node[below] {$Z_1$};
But this solution is time consuming. Is there any efficient way to add cell identifier to each cell?
documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
draw (-4,2.5) node[below] {$Z_1$};
end{tikzpicture}
end{document}
This what I want to draw:

tikz-pgf formatting tikz-styles tikz-arrows
add a comment |
I made a grid with TikZ. I would like to add the cell number in each cell (in the middle of each cell),
I used this command
draw (-4,2.5) node[below] {$Z_1$};
But this solution is time consuming. Is there any efficient way to add cell identifier to each cell?
documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
draw (-4,2.5) node[below] {$Z_1$};
end{tikzpicture}
end{document}
This what I want to draw:

tikz-pgf formatting tikz-styles tikz-arrows
I made a grid with TikZ. I would like to add the cell number in each cell (in the middle of each cell),
I used this command
draw (-4,2.5) node[below] {$Z_1$};
But this solution is time consuming. Is there any efficient way to add cell identifier to each cell?
documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
draw (-4,2.5) node[below] {$Z_1$};
end{tikzpicture}
end{document}
This what I want to draw:

tikz-pgf formatting tikz-styles tikz-arrows
tikz-pgf formatting tikz-styles tikz-arrows
edited 1 hour ago
Sebastiano
9,99341858
9,99341858
asked 1 hour ago
Heba MohsenHeba Mohsen
584
584
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
For example:

documentclass[tikz]{standalone} % tikz loads graphicx
begin{document}
begin{tikzpicture}[
declare function={boxW=1.2cm;},
box/.style={minimum size=boxW,draw},
]
foreach x in {0,...,15}
{
ifnumx=0
node [box,fill=blue!20] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
else
node [box] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
fi
}
end{tikzpicture}
end{document}
add a comment |
Since your MWE includes an image, with a grid that is superimposed on it, I considered that you wanted to draw the grid over this image.
This is what I get, is that what you want?

documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[xstep=2.5cm,ystep=1.2,blue,very thin] (-5,-2.4) grid (5,2.4);
foreach x [evaluate=x as xx using x*2.5-3.75]in {0,...,3}{
foreach y [evaluate =y as label using int(x-4*y),
evaluate=y as yy using y*1.2+1.8]in {0,-1,...,-3}{
draw (xx,yy) node[below] {$C_{label}$};
} }
end{tikzpicture}
end{document}
add a comment |
This proposal combines two answers by @percusse:
This nice answer allows you to set up a matrix withforeachloops.
This nice answer allows you to fill entries specified in a list.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{etoolbox}
usetikzlibrary{matrix}
begin{document}
newcommand{setupmatrix}[3]{%
letmymatrixcontentempty
foreach j in {1,...,#2}{
foreach i [evaluate=i as k using {int(#3*(j-1)+i-1)}]
in {1,...,#3} {%
begingroupedefx{endgroup
noexpandgapptonoexpandmymatrixcontent{
#1_{k} &}}x
}%
gapptomymatrixcontent{\}%
}
} % setupmatrix{<entry>}{<number of rows>}{<number of columns>}
setupmatrix{Z}{4}{8}
tikzset{myfill/.style args={#1|#2}{row #2 column #1/.style={nodes={fill=blue!30}}}}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
matrix (a) [ampersand replacement=&,matrix of math nodes,
nodes={minimum width=1.2cm,minimum height=1.2cm},
myfill/.list={1|1,3|2,6|3}]{
mymatrixcontent
};
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%2f474581%2fis-there-any-efficient-way-to-add-cell-identifier-to-each-cell-in-tikz%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
For example:

documentclass[tikz]{standalone} % tikz loads graphicx
begin{document}
begin{tikzpicture}[
declare function={boxW=1.2cm;},
box/.style={minimum size=boxW,draw},
]
foreach x in {0,...,15}
{
ifnumx=0
node [box,fill=blue!20] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
else
node [box] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
fi
}
end{tikzpicture}
end{document}
add a comment |
For example:

documentclass[tikz]{standalone} % tikz loads graphicx
begin{document}
begin{tikzpicture}[
declare function={boxW=1.2cm;},
box/.style={minimum size=boxW,draw},
]
foreach x in {0,...,15}
{
ifnumx=0
node [box,fill=blue!20] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
else
node [box] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
fi
}
end{tikzpicture}
end{document}
add a comment |
For example:

documentclass[tikz]{standalone} % tikz loads graphicx
begin{document}
begin{tikzpicture}[
declare function={boxW=1.2cm;},
box/.style={minimum size=boxW,draw},
]
foreach x in {0,...,15}
{
ifnumx=0
node [box,fill=blue!20] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
else
node [box] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
fi
}
end{tikzpicture}
end{document}
For example:

documentclass[tikz]{standalone} % tikz loads graphicx
begin{document}
begin{tikzpicture}[
declare function={boxW=1.2cm;},
box/.style={minimum size=boxW,draw},
]
foreach x in {0,...,15}
{
ifnumx=0
node [box,fill=blue!20] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
else
node [box] at ({mod(x,4)*boxW}, {-ceil((x+1)/4)*boxW}) {$C_{x}$};
fi
}
end{tikzpicture}
end{document}
answered 1 hour ago
Torbjørn T.Torbjørn T.
157k13251439
157k13251439
add a comment |
add a comment |
Since your MWE includes an image, with a grid that is superimposed on it, I considered that you wanted to draw the grid over this image.
This is what I get, is that what you want?

documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[xstep=2.5cm,ystep=1.2,blue,very thin] (-5,-2.4) grid (5,2.4);
foreach x [evaluate=x as xx using x*2.5-3.75]in {0,...,3}{
foreach y [evaluate =y as label using int(x-4*y),
evaluate=y as yy using y*1.2+1.8]in {0,-1,...,-3}{
draw (xx,yy) node[below] {$C_{label}$};
} }
end{tikzpicture}
end{document}
add a comment |
Since your MWE includes an image, with a grid that is superimposed on it, I considered that you wanted to draw the grid over this image.
This is what I get, is that what you want?

documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[xstep=2.5cm,ystep=1.2,blue,very thin] (-5,-2.4) grid (5,2.4);
foreach x [evaluate=x as xx using x*2.5-3.75]in {0,...,3}{
foreach y [evaluate =y as label using int(x-4*y),
evaluate=y as yy using y*1.2+1.8]in {0,-1,...,-3}{
draw (xx,yy) node[below] {$C_{label}$};
} }
end{tikzpicture}
end{document}
add a comment |
Since your MWE includes an image, with a grid that is superimposed on it, I considered that you wanted to draw the grid over this image.
This is what I get, is that what you want?

documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[xstep=2.5cm,ystep=1.2,blue,very thin] (-5,-2.4) grid (5,2.4);
foreach x [evaluate=x as xx using x*2.5-3.75]in {0,...,3}{
foreach y [evaluate =y as label using int(x-4*y),
evaluate=y as yy using y*1.2+1.8]in {0,-1,...,-3}{
draw (xx,yy) node[below] {$C_{label}$};
} }
end{tikzpicture}
end{document}
Since your MWE includes an image, with a grid that is superimposed on it, I considered that you wanted to draw the grid over this image.
This is what I get, is that what you want?

documentclass[tikz]{standalone}
usepackage{graphicx} % for example images
begin{document}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
tikzstyle{myLabel}=[draw=black, circle, fill=white]
tikzstyle{myLine}=[draw=blue, double]
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[xstep=2.5cm,ystep=1.2,blue,very thin] (-5,-2.4) grid (5,2.4);
foreach x [evaluate=x as xx using x*2.5-3.75]in {0,...,3}{
foreach y [evaluate =y as label using int(x-4*y),
evaluate=y as yy using y*1.2+1.8]in {0,-1,...,-3}{
draw (xx,yy) node[below] {$C_{label}$};
} }
end{tikzpicture}
end{document}
answered 1 hour ago
AndréCAndréC
8,99411447
8,99411447
add a comment |
add a comment |
This proposal combines two answers by @percusse:
This nice answer allows you to set up a matrix withforeachloops.
This nice answer allows you to fill entries specified in a list.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{etoolbox}
usetikzlibrary{matrix}
begin{document}
newcommand{setupmatrix}[3]{%
letmymatrixcontentempty
foreach j in {1,...,#2}{
foreach i [evaluate=i as k using {int(#3*(j-1)+i-1)}]
in {1,...,#3} {%
begingroupedefx{endgroup
noexpandgapptonoexpandmymatrixcontent{
#1_{k} &}}x
}%
gapptomymatrixcontent{\}%
}
} % setupmatrix{<entry>}{<number of rows>}{<number of columns>}
setupmatrix{Z}{4}{8}
tikzset{myfill/.style args={#1|#2}{row #2 column #1/.style={nodes={fill=blue!30}}}}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
matrix (a) [ampersand replacement=&,matrix of math nodes,
nodes={minimum width=1.2cm,minimum height=1.2cm},
myfill/.list={1|1,3|2,6|3}]{
mymatrixcontent
};
end{tikzpicture}
end{document}

add a comment |
This proposal combines two answers by @percusse:
This nice answer allows you to set up a matrix withforeachloops.
This nice answer allows you to fill entries specified in a list.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{etoolbox}
usetikzlibrary{matrix}
begin{document}
newcommand{setupmatrix}[3]{%
letmymatrixcontentempty
foreach j in {1,...,#2}{
foreach i [evaluate=i as k using {int(#3*(j-1)+i-1)}]
in {1,...,#3} {%
begingroupedefx{endgroup
noexpandgapptonoexpandmymatrixcontent{
#1_{k} &}}x
}%
gapptomymatrixcontent{\}%
}
} % setupmatrix{<entry>}{<number of rows>}{<number of columns>}
setupmatrix{Z}{4}{8}
tikzset{myfill/.style args={#1|#2}{row #2 column #1/.style={nodes={fill=blue!30}}}}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
matrix (a) [ampersand replacement=&,matrix of math nodes,
nodes={minimum width=1.2cm,minimum height=1.2cm},
myfill/.list={1|1,3|2,6|3}]{
mymatrixcontent
};
end{tikzpicture}
end{document}

add a comment |
This proposal combines two answers by @percusse:
This nice answer allows you to set up a matrix withforeachloops.
This nice answer allows you to fill entries specified in a list.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{etoolbox}
usetikzlibrary{matrix}
begin{document}
newcommand{setupmatrix}[3]{%
letmymatrixcontentempty
foreach j in {1,...,#2}{
foreach i [evaluate=i as k using {int(#3*(j-1)+i-1)}]
in {1,...,#3} {%
begingroupedefx{endgroup
noexpandgapptonoexpandmymatrixcontent{
#1_{k} &}}x
}%
gapptomymatrixcontent{\}%
}
} % setupmatrix{<entry>}{<number of rows>}{<number of columns>}
setupmatrix{Z}{4}{8}
tikzset{myfill/.style args={#1|#2}{row #2 column #1/.style={nodes={fill=blue!30}}}}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
matrix (a) [ampersand replacement=&,matrix of math nodes,
nodes={minimum width=1.2cm,minimum height=1.2cm},
myfill/.list={1|1,3|2,6|3}]{
mymatrixcontent
};
end{tikzpicture}
end{document}

This proposal combines two answers by @percusse:
This nice answer allows you to set up a matrix withforeachloops.
This nice answer allows you to fill entries specified in a list.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{etoolbox}
usetikzlibrary{matrix}
begin{document}
newcommand{setupmatrix}[3]{%
letmymatrixcontentempty
foreach j in {1,...,#2}{
foreach i [evaluate=i as k using {int(#3*(j-1)+i-1)}]
in {1,...,#3} {%
begingroupedefx{endgroup
noexpandgapptonoexpandmymatrixcontent{
#1_{k} &}}x
}%
gapptomymatrixcontent{\}%
}
} % setupmatrix{<entry>}{<number of rows>}{<number of columns>}
setupmatrix{Z}{4}{8}
tikzset{myfill/.style args={#1|#2}{row #2 column #1/.style={nodes={fill=blue!30}}}}
begin{tikzpicture}[every label/.style={fill=white, inner sep=1mm}]
% styles
draw (0,0) node[inner sep=0] {includegraphics[width=10cm]{example-image-a}};
draw[step=1.2cm,blue,very thin] (-5,-2.5) grid (5,2.4);
matrix (a) [ampersand replacement=&,matrix of math nodes,
nodes={minimum width=1.2cm,minimum height=1.2cm},
myfill/.list={1|1,3|2,6|3}]{
mymatrixcontent
};
end{tikzpicture}
end{document}

answered 55 mins ago
marmotmarmot
99.4k4115220
99.4k4115220
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%2f474581%2fis-there-any-efficient-way-to-add-cell-identifier-to-each-cell-in-tikz%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