Grid using TikZ












10















I'm using the code below to generate the grid, however it's not connecting all points in the grid.



Could anyone help with this? Thank you!



enter image description here



begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}

foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;

end{tikzpicture}









share|improve this question




















  • 1





    Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557

    – nidhin
    Nov 16 '18 at 12:12











  • There is no need to do pgfmathtruncatemacro {label}{x y}, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};} without any detour.

    – marmot
    Nov 16 '18 at 14:00
















10















I'm using the code below to generate the grid, however it's not connecting all points in the grid.



Could anyone help with this? Thank you!



enter image description here



begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}

foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;

end{tikzpicture}









share|improve this question




















  • 1





    Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557

    – nidhin
    Nov 16 '18 at 12:12











  • There is no need to do pgfmathtruncatemacro {label}{x y}, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};} without any detour.

    – marmot
    Nov 16 '18 at 14:00














10












10








10


1






I'm using the code below to generate the grid, however it's not connecting all points in the grid.



Could anyone help with this? Thank you!



enter image description here



begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}

foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;

end{tikzpicture}









share|improve this question
















I'm using the code below to generate the grid, however it's not connecting all points in the grid.



Could anyone help with this? Thank you!



enter image description here



begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}

foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;

end{tikzpicture}






tikz-pgf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 12:24









AndréC

8,78911447




8,78911447










asked Nov 16 '18 at 11:57









ioanaioana

513




513








  • 1





    Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557

    – nidhin
    Nov 16 '18 at 12:12











  • There is no need to do pgfmathtruncatemacro {label}{x y}, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};} without any detour.

    – marmot
    Nov 16 '18 at 14:00














  • 1





    Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557

    – nidhin
    Nov 16 '18 at 12:12











  • There is no need to do pgfmathtruncatemacro {label}{x y}, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};} without any detour.

    – marmot
    Nov 16 '18 at 14:00








1




1





Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557

– nidhin
Nov 16 '18 at 12:12





Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557

– nidhin
Nov 16 '18 at 12:12













There is no need to do pgfmathtruncatemacro {label}{x y}, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};} without any detour.

– marmot
Nov 16 '18 at 14:00





There is no need to do pgfmathtruncatemacro {label}{x y}, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};} without any detour.

– marmot
Nov 16 '18 at 14:00










3 Answers
3






active

oldest

votes


















10














Unsurprisingly, a grid can be drawn with grid... (and there is no need to do pgfmathtruncatemacro {label}{x y}).



documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer































    6














    The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:



    draw (xy)--(xyi)


    Indeed, your loop generates a counter [count=yi] in {1,2} which starts at 1 and therefore during the first iteration with x=1 and y =1, you generate this x=1 yi=1, etc.



    Assuming you want the same result as @DũngVũ, here is another way to do it:



    grid



    documentclass[crop,tikz,border=5mm]{standalone}
    begin{document}

    usetikzlibrary{positioning,calc}
    tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]

    begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
    foreach x in {1, 2, 3}
    foreach y in {1, 2, 3}
    {pgfmathtruncatemacro {label}{xy}
    node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
    }

    foreach x in {1,2,3}
    foreach y [count=yi from 2] in {1,2}
    path (xy)edge(xyi)(yx)edge(yix);

    end{tikzpicture}
    end{document}





    share|improve this answer


























    • Thank you! It is what I was looking for!

      – ioana
      Nov 16 '18 at 13:15



















    5














    Do you mean this?



    documentclass{article}
    usepackage{tikz}
    begin{document}
    begin{tikzpicture}
    foreach x in {1, 2, 3}
    foreach y in {1, 2}
    draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
    foreach x in {1, 2}
    foreach y in {1, 2, 3}
    draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
    foreach x in {1, 2, 3}
    foreach y in {1, 2, 3} {
    pgfmathtruncatemacro {label}{xy}
    fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
    draw (1.5*x,1.5*y) circle (0.5cm);
    node (xy) at (1.5*x,1.5*y) {$U_{label}$};
    }
    end{tikzpicture}
    end{document}


    enter image description here



    Hope this will help!






    share|improve this answer
























    • Yes, this is what I wanted. Thank you!!

      – ioana
      Nov 16 '18 at 13:14











    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%2f460284%2fgrid-using-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









    10














    Unsurprisingly, a grid can be drawn with grid... (and there is no need to do pgfmathtruncatemacro {label}{x y}).



    documentclass[tikz,border=3.14mm]{standalone}
    begin{document}
    begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
    draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
    foreach x in {1, 2, 3}
    foreach y in {1, 2, 3}
    {
    node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer




























      10














      Unsurprisingly, a grid can be drawn with grid... (and there is no need to do pgfmathtruncatemacro {label}{x y}).



      documentclass[tikz,border=3.14mm]{standalone}
      begin{document}
      begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
      draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
      foreach x in {1, 2, 3}
      foreach y in {1, 2, 3}
      {
      node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer


























        10












        10








        10







        Unsurprisingly, a grid can be drawn with grid... (and there is no need to do pgfmathtruncatemacro {label}{x y}).



        documentclass[tikz,border=3.14mm]{standalone}
        begin{document}
        begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
        draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
        foreach x in {1, 2, 3}
        foreach y in {1, 2, 3}
        {
        node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
        end{tikzpicture}
        end{document}


        enter image description here






        share|improve this answer













        Unsurprisingly, a grid can be drawn with grid... (and there is no need to do pgfmathtruncatemacro {label}{x y}).



        documentclass[tikz,border=3.14mm]{standalone}
        begin{document}
        begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
        draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
        foreach x in {1, 2, 3}
        foreach y in {1, 2, 3}
        {
        node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
        end{tikzpicture}
        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 15:06









        marmotmarmot

        95.7k4110210




        95.7k4110210























            6














            The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:



            draw (xy)--(xyi)


            Indeed, your loop generates a counter [count=yi] in {1,2} which starts at 1 and therefore during the first iteration with x=1 and y =1, you generate this x=1 yi=1, etc.



            Assuming you want the same result as @DũngVũ, here is another way to do it:



            grid



            documentclass[crop,tikz,border=5mm]{standalone}
            begin{document}

            usetikzlibrary{positioning,calc}
            tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]

            begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3}
            {pgfmathtruncatemacro {label}{xy}
            node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }

            foreach x in {1,2,3}
            foreach y [count=yi from 2] in {1,2}
            path (xy)edge(xyi)(yx)edge(yix);

            end{tikzpicture}
            end{document}





            share|improve this answer


























            • Thank you! It is what I was looking for!

              – ioana
              Nov 16 '18 at 13:15
















            6














            The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:



            draw (xy)--(xyi)


            Indeed, your loop generates a counter [count=yi] in {1,2} which starts at 1 and therefore during the first iteration with x=1 and y =1, you generate this x=1 yi=1, etc.



            Assuming you want the same result as @DũngVũ, here is another way to do it:



            grid



            documentclass[crop,tikz,border=5mm]{standalone}
            begin{document}

            usetikzlibrary{positioning,calc}
            tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]

            begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3}
            {pgfmathtruncatemacro {label}{xy}
            node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }

            foreach x in {1,2,3}
            foreach y [count=yi from 2] in {1,2}
            path (xy)edge(xyi)(yx)edge(yix);

            end{tikzpicture}
            end{document}





            share|improve this answer


























            • Thank you! It is what I was looking for!

              – ioana
              Nov 16 '18 at 13:15














            6












            6








            6







            The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:



            draw (xy)--(xyi)


            Indeed, your loop generates a counter [count=yi] in {1,2} which starts at 1 and therefore during the first iteration with x=1 and y =1, you generate this x=1 yi=1, etc.



            Assuming you want the same result as @DũngVũ, here is another way to do it:



            grid



            documentclass[crop,tikz,border=5mm]{standalone}
            begin{document}

            usetikzlibrary{positioning,calc}
            tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]

            begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3}
            {pgfmathtruncatemacro {label}{xy}
            node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }

            foreach x in {1,2,3}
            foreach y [count=yi from 2] in {1,2}
            path (xy)edge(xyi)(yx)edge(yix);

            end{tikzpicture}
            end{document}





            share|improve this answer















            The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:



            draw (xy)--(xyi)


            Indeed, your loop generates a counter [count=yi] in {1,2} which starts at 1 and therefore during the first iteration with x=1 and y =1, you generate this x=1 yi=1, etc.



            Assuming you want the same result as @DũngVũ, here is another way to do it:



            grid



            documentclass[crop,tikz,border=5mm]{standalone}
            begin{document}

            usetikzlibrary{positioning,calc}
            tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]

            begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3}
            {pgfmathtruncatemacro {label}{xy}
            node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }

            foreach x in {1,2,3}
            foreach y [count=yi from 2] in {1,2}
            path (xy)edge(xyi)(yx)edge(yix);

            end{tikzpicture}
            end{document}






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 16 '18 at 15:50

























            answered Nov 16 '18 at 12:52









            AndréCAndréC

            8,78911447




            8,78911447













            • Thank you! It is what I was looking for!

              – ioana
              Nov 16 '18 at 13:15



















            • Thank you! It is what I was looking for!

              – ioana
              Nov 16 '18 at 13:15

















            Thank you! It is what I was looking for!

            – ioana
            Nov 16 '18 at 13:15





            Thank you! It is what I was looking for!

            – ioana
            Nov 16 '18 at 13:15











            5














            Do you mean this?



            documentclass{article}
            usepackage{tikz}
            begin{document}
            begin{tikzpicture}
            foreach x in {1, 2, 3}
            foreach y in {1, 2}
            draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
            foreach x in {1, 2}
            foreach y in {1, 2, 3}
            draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3} {
            pgfmathtruncatemacro {label}{xy}
            fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
            draw (1.5*x,1.5*y) circle (0.5cm);
            node (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }
            end{tikzpicture}
            end{document}


            enter image description here



            Hope this will help!






            share|improve this answer
























            • Yes, this is what I wanted. Thank you!!

              – ioana
              Nov 16 '18 at 13:14
















            5














            Do you mean this?



            documentclass{article}
            usepackage{tikz}
            begin{document}
            begin{tikzpicture}
            foreach x in {1, 2, 3}
            foreach y in {1, 2}
            draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
            foreach x in {1, 2}
            foreach y in {1, 2, 3}
            draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3} {
            pgfmathtruncatemacro {label}{xy}
            fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
            draw (1.5*x,1.5*y) circle (0.5cm);
            node (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }
            end{tikzpicture}
            end{document}


            enter image description here



            Hope this will help!






            share|improve this answer
























            • Yes, this is what I wanted. Thank you!!

              – ioana
              Nov 16 '18 at 13:14














            5












            5








            5







            Do you mean this?



            documentclass{article}
            usepackage{tikz}
            begin{document}
            begin{tikzpicture}
            foreach x in {1, 2, 3}
            foreach y in {1, 2}
            draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
            foreach x in {1, 2}
            foreach y in {1, 2, 3}
            draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3} {
            pgfmathtruncatemacro {label}{xy}
            fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
            draw (1.5*x,1.5*y) circle (0.5cm);
            node (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }
            end{tikzpicture}
            end{document}


            enter image description here



            Hope this will help!






            share|improve this answer













            Do you mean this?



            documentclass{article}
            usepackage{tikz}
            begin{document}
            begin{tikzpicture}
            foreach x in {1, 2, 3}
            foreach y in {1, 2}
            draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
            foreach x in {1, 2}
            foreach y in {1, 2, 3}
            draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
            foreach x in {1, 2, 3}
            foreach y in {1, 2, 3} {
            pgfmathtruncatemacro {label}{xy}
            fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
            draw (1.5*x,1.5*y) circle (0.5cm);
            node (xy) at (1.5*x,1.5*y) {$U_{label}$};
            }
            end{tikzpicture}
            end{document}


            enter image description here



            Hope this will help!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '18 at 12:14









            JouleVJouleV

            2,499628




            2,499628













            • Yes, this is what I wanted. Thank you!!

              – ioana
              Nov 16 '18 at 13:14



















            • Yes, this is what I wanted. Thank you!!

              – ioana
              Nov 16 '18 at 13:14

















            Yes, this is what I wanted. Thank you!!

            – ioana
            Nov 16 '18 at 13:14





            Yes, this is what I wanted. Thank you!!

            – ioana
            Nov 16 '18 at 13:14


















            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%2f460284%2fgrid-using-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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()