Is there any efficient way to add cell identifier to each cell in TikZ?












5















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:



enter image description here










share|improve this question





























    5















    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:



    enter image description here










    share|improve this question



























      5












      5








      5








      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:



      enter image description here










      share|improve this question
















      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:



      enter image description here







      tikz-pgf formatting tikz-styles tikz-arrows






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      Sebastiano

      9,99341858




      9,99341858










      asked 1 hour ago









      Heba MohsenHeba Mohsen

      584




      584






















          3 Answers
          3






          active

          oldest

          votes


















          3














          For example:



          enter image description here



          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}





          share|improve this answer































            2














            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?



            scrennshot



            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}





            share|improve this answer































              2














              This proposal combines two answers by @percusse:





              1. This nice answer allows you to set up a matrix with foreach loops.


              2. 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}


              enter image description here






              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
                });


                }
                });














                draft saved

                draft discarded


















                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









                3














                For example:



                enter image description here



                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}





                share|improve this answer




























                  3














                  For example:



                  enter image description here



                  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}





                  share|improve this answer


























                    3












                    3








                    3







                    For example:



                    enter image description here



                    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}





                    share|improve this answer













                    For example:



                    enter image description here



                    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}






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    Torbjørn T.Torbjørn T.

                    157k13251439




                    157k13251439























                        2














                        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?



                        scrennshot



                        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}





                        share|improve this answer




























                          2














                          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?



                          scrennshot



                          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}





                          share|improve this answer


























                            2












                            2








                            2







                            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?



                            scrennshot



                            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}





                            share|improve this answer













                            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?



                            scrennshot



                            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}






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            AndréCAndréC

                            8,99411447




                            8,99411447























                                2














                                This proposal combines two answers by @percusse:





                                1. This nice answer allows you to set up a matrix with foreach loops.


                                2. 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}


                                enter image description here






                                share|improve this answer




























                                  2














                                  This proposal combines two answers by @percusse:





                                  1. This nice answer allows you to set up a matrix with foreach loops.


                                  2. 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}


                                  enter image description here






                                  share|improve this answer


























                                    2












                                    2








                                    2







                                    This proposal combines two answers by @percusse:





                                    1. This nice answer allows you to set up a matrix with foreach loops.


                                    2. 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}


                                    enter image description here






                                    share|improve this answer













                                    This proposal combines two answers by @percusse:





                                    1. This nice answer allows you to set up a matrix with foreach loops.


                                    2. 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}


                                    enter image description here







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 55 mins ago









                                    marmotmarmot

                                    99.4k4115220




                                    99.4k4115220






























                                        draft saved

                                        draft discarded




















































                                        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%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





















































                                        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

                                        Callistus I

                                        Tabula Rosettana

                                        How to label and detect the document text images