Drawing Grid Lines using foreach












4














I am trying to draw gridlines inside a square. Here is my code:



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.15}

begin{document}

begin{figure}[ht]

centering

begin{tikzpicture}[scale=1.25,line width=1pt]
begin{axis}[
color= white,
xmin=-28.9,
xmax=28.9,
ymin=-28.9,
ymax=28.9,
axis equal image,
axis lines=middle,
]

foreach x in {-24,..., 24}
{draw[thin, gray] (x,-24) -- (x,24);}

draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
(-24,-24);

node[black, below] at (24,-24) {$(1,0)$};

node[black, below] at (-24,-24) {$(0,0)$};

node[black, above] at (-24,24) {$(0,1)$};

node[black, above] at (24,24) {$(1,1)$};

end{axis}
end{tikzpicture}

end{figure}

end{document}


This code, however, will not compile. My goal is to make a square with a 24 x 24 grid.










share|improve this question






















  • No grid comes up when I use this. It only produces the square
    – Aiden Kenny
    Dec 16 at 9:07
















4














I am trying to draw gridlines inside a square. Here is my code:



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.15}

begin{document}

begin{figure}[ht]

centering

begin{tikzpicture}[scale=1.25,line width=1pt]
begin{axis}[
color= white,
xmin=-28.9,
xmax=28.9,
ymin=-28.9,
ymax=28.9,
axis equal image,
axis lines=middle,
]

foreach x in {-24,..., 24}
{draw[thin, gray] (x,-24) -- (x,24);}

draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
(-24,-24);

node[black, below] at (24,-24) {$(1,0)$};

node[black, below] at (-24,-24) {$(0,0)$};

node[black, above] at (-24,24) {$(0,1)$};

node[black, above] at (24,24) {$(1,1)$};

end{axis}
end{tikzpicture}

end{figure}

end{document}


This code, however, will not compile. My goal is to make a square with a 24 x 24 grid.










share|improve this question






















  • No grid comes up when I use this. It only produces the square
    – Aiden Kenny
    Dec 16 at 9:07














4












4








4


1





I am trying to draw gridlines inside a square. Here is my code:



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.15}

begin{document}

begin{figure}[ht]

centering

begin{tikzpicture}[scale=1.25,line width=1pt]
begin{axis}[
color= white,
xmin=-28.9,
xmax=28.9,
ymin=-28.9,
ymax=28.9,
axis equal image,
axis lines=middle,
]

foreach x in {-24,..., 24}
{draw[thin, gray] (x,-24) -- (x,24);}

draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
(-24,-24);

node[black, below] at (24,-24) {$(1,0)$};

node[black, below] at (-24,-24) {$(0,0)$};

node[black, above] at (-24,24) {$(0,1)$};

node[black, above] at (24,24) {$(1,1)$};

end{axis}
end{tikzpicture}

end{figure}

end{document}


This code, however, will not compile. My goal is to make a square with a 24 x 24 grid.










share|improve this question













I am trying to draw gridlines inside a square. Here is my code:



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.15}

begin{document}

begin{figure}[ht]

centering

begin{tikzpicture}[scale=1.25,line width=1pt]
begin{axis}[
color= white,
xmin=-28.9,
xmax=28.9,
ymin=-28.9,
ymax=28.9,
axis equal image,
axis lines=middle,
]

foreach x in {-24,..., 24}
{draw[thin, gray] (x,-24) -- (x,24);}

draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
(-24,-24);

node[black, below] at (24,-24) {$(1,0)$};

node[black, below] at (-24,-24) {$(0,0)$};

node[black, above] at (-24,24) {$(0,1)$};

node[black, above] at (24,24) {$(1,1)$};

end{axis}
end{tikzpicture}

end{figure}

end{document}


This code, however, will not compile. My goal is to make a square with a 24 x 24 grid.







tikz-pgf foreach






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 16 at 9:02









Aiden Kenny

1685




1685












  • No grid comes up when I use this. It only produces the square
    – Aiden Kenny
    Dec 16 at 9:07


















  • No grid comes up when I use this. It only produces the square
    – Aiden Kenny
    Dec 16 at 9:07
















No grid comes up when I use this. It only produces the square
– Aiden Kenny
Dec 16 at 9:07




No grid comes up when I use this. It only produces the square
– Aiden Kenny
Dec 16 at 9:07










2 Answers
2






active

oldest

votes


















6














Works fine if you use pgfplotsinvokeforeach instead of foreach:



enter image description here



Notes:




  • I would suggest you try the grid options built into pgfplots and tikz.

  • All the code you showing does not require pgfplots so you can eliminate the axis environment. So, unless there is other functionality that is not shown in the MWE, you should consider the non-axis environment version which uses foreach.


References:




  • foreach not behaving in axis environment


  • Tikz foreach loop and coordinate computation.


Code: pgfplots



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.15}

begin{document}
%
%begin{figure}[ht]
%
%centering
%
begin{tikzpicture}%[scale=1.25,line width=1pt]
begin{axis}[
color= white,
xmin=-28.9,
xmax=28.9,
ymin=-28.9,
ymax=28.9,
axis equal image,
axis lines=middle,
]

pgfplotsinvokeforeach {-24,...,24} {%
draw[thin, gray] (#1,-24) -- (#1,24);
}

draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
(-24,-24);

node[black, below] at (24,-24) {$(1,0)$};

node[black, below] at (-24,-24) {$(0,0)$};

node[black, above] at (-24,24) {$(0,1)$};

node[black, above] at (24,24) {$(1,1)$};

end{axis}
end{tikzpicture}%
%
%end{figure}
%
end{document}


Code: no pgfplots



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.15}

begin{document}
begin{tikzpicture}[scale=0.10]

foreach x in {-24,...,24} {%
draw[thin, gray] (x,-24) -- (x,24);
}

draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
(-24,-24);

node[black, below] at (24,-24) {$(1,0)$};

node[black, below] at (-24,-24) {$(0,0)$};

node[black, above] at (-24,24) {$(0,1)$};

node[black, above] at (24,24) {$(1,1)$};

end{tikzpicture}%
end{document}





share|improve this answer























  • Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
    – Aiden Kenny
    Dec 23 at 17:09










  • @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
    – Peter Grill
    Dec 23 at 17:58












  • @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
    – Peter Grill
    Dec 23 at 18:00



















6














Two other options without pgfplots, one without foreach and one with foreach:



documentclass[tikz,border=2mm]{standalone} 
usetikzlibrary{positioning}

begin{document}
begin{tikzpicture}
draw (0,0) grid (24,24);
node[above right] at (24,24) {$(1,1)$};
node[above left] at (0,24) {$(0,1)$};
node[below left] at (0,0) {$(0,0)$};
node[below right] at (24,0) {$(1,0)$};
end{tikzpicture}

begin{tikzpicture}
foreach i in {0,...,24}{
draw (i,0) -- ++(90:24);
draw (0,i) -- ++(0:24);
}
node[above right] at (24,24) {$(1,1)$};
node[above left] at (0,24) {$(0,1)$};
node[below left] at (0,0) {$(0,0)$};
node[below right] at (24,0) {$(1,0)$};
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%2f466054%2fdrawing-grid-lines-using-foreach%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    Works fine if you use pgfplotsinvokeforeach instead of foreach:



    enter image description here



    Notes:




    • I would suggest you try the grid options built into pgfplots and tikz.

    • All the code you showing does not require pgfplots so you can eliminate the axis environment. So, unless there is other functionality that is not shown in the MWE, you should consider the non-axis environment version which uses foreach.


    References:




    • foreach not behaving in axis environment


    • Tikz foreach loop and coordinate computation.


    Code: pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    %
    %begin{figure}[ht]
    %
    %centering
    %
    begin{tikzpicture}%[scale=1.25,line width=1pt]
    begin{axis}[
    color= white,
    xmin=-28.9,
    xmax=28.9,
    ymin=-28.9,
    ymax=28.9,
    axis equal image,
    axis lines=middle,
    ]

    pgfplotsinvokeforeach {-24,...,24} {%
    draw[thin, gray] (#1,-24) -- (#1,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{axis}
    end{tikzpicture}%
    %
    %end{figure}
    %
    end{document}


    Code: no pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    begin{tikzpicture}[scale=0.10]

    foreach x in {-24,...,24} {%
    draw[thin, gray] (x,-24) -- (x,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{tikzpicture}%
    end{document}





    share|improve this answer























    • Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
      – Aiden Kenny
      Dec 23 at 17:09










    • @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
      – Peter Grill
      Dec 23 at 17:58












    • @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
      – Peter Grill
      Dec 23 at 18:00
















    6














    Works fine if you use pgfplotsinvokeforeach instead of foreach:



    enter image description here



    Notes:




    • I would suggest you try the grid options built into pgfplots and tikz.

    • All the code you showing does not require pgfplots so you can eliminate the axis environment. So, unless there is other functionality that is not shown in the MWE, you should consider the non-axis environment version which uses foreach.


    References:




    • foreach not behaving in axis environment


    • Tikz foreach loop and coordinate computation.


    Code: pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    %
    %begin{figure}[ht]
    %
    %centering
    %
    begin{tikzpicture}%[scale=1.25,line width=1pt]
    begin{axis}[
    color= white,
    xmin=-28.9,
    xmax=28.9,
    ymin=-28.9,
    ymax=28.9,
    axis equal image,
    axis lines=middle,
    ]

    pgfplotsinvokeforeach {-24,...,24} {%
    draw[thin, gray] (#1,-24) -- (#1,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{axis}
    end{tikzpicture}%
    %
    %end{figure}
    %
    end{document}


    Code: no pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    begin{tikzpicture}[scale=0.10]

    foreach x in {-24,...,24} {%
    draw[thin, gray] (x,-24) -- (x,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{tikzpicture}%
    end{document}





    share|improve this answer























    • Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
      – Aiden Kenny
      Dec 23 at 17:09










    • @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
      – Peter Grill
      Dec 23 at 17:58












    • @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
      – Peter Grill
      Dec 23 at 18:00














    6












    6








    6






    Works fine if you use pgfplotsinvokeforeach instead of foreach:



    enter image description here



    Notes:




    • I would suggest you try the grid options built into pgfplots and tikz.

    • All the code you showing does not require pgfplots so you can eliminate the axis environment. So, unless there is other functionality that is not shown in the MWE, you should consider the non-axis environment version which uses foreach.


    References:




    • foreach not behaving in axis environment


    • Tikz foreach loop and coordinate computation.


    Code: pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    %
    %begin{figure}[ht]
    %
    %centering
    %
    begin{tikzpicture}%[scale=1.25,line width=1pt]
    begin{axis}[
    color= white,
    xmin=-28.9,
    xmax=28.9,
    ymin=-28.9,
    ymax=28.9,
    axis equal image,
    axis lines=middle,
    ]

    pgfplotsinvokeforeach {-24,...,24} {%
    draw[thin, gray] (#1,-24) -- (#1,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{axis}
    end{tikzpicture}%
    %
    %end{figure}
    %
    end{document}


    Code: no pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    begin{tikzpicture}[scale=0.10]

    foreach x in {-24,...,24} {%
    draw[thin, gray] (x,-24) -- (x,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{tikzpicture}%
    end{document}





    share|improve this answer














    Works fine if you use pgfplotsinvokeforeach instead of foreach:



    enter image description here



    Notes:




    • I would suggest you try the grid options built into pgfplots and tikz.

    • All the code you showing does not require pgfplots so you can eliminate the axis environment. So, unless there is other functionality that is not shown in the MWE, you should consider the non-axis environment version which uses foreach.


    References:




    • foreach not behaving in axis environment


    • Tikz foreach loop and coordinate computation.


    Code: pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    %
    %begin{figure}[ht]
    %
    %centering
    %
    begin{tikzpicture}%[scale=1.25,line width=1pt]
    begin{axis}[
    color= white,
    xmin=-28.9,
    xmax=28.9,
    ymin=-28.9,
    ymax=28.9,
    axis equal image,
    axis lines=middle,
    ]

    pgfplotsinvokeforeach {-24,...,24} {%
    draw[thin, gray] (#1,-24) -- (#1,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{axis}
    end{tikzpicture}%
    %
    %end{figure}
    %
    end{document}


    Code: no pgfplots



    documentclass{article}
    usepackage{pgfplots}
    pgfplotsset{compat=1.15}

    begin{document}
    begin{tikzpicture}[scale=0.10]

    foreach x in {-24,...,24} {%
    draw[thin, gray] (x,-24) -- (x,24);
    }

    draw[black, thin] (-24,-24) -- (-24,24) -- (24,24) -- (24, -24) --
    (-24,-24);

    node[black, below] at (24,-24) {$(1,0)$};

    node[black, below] at (-24,-24) {$(0,0)$};

    node[black, above] at (-24,24) {$(0,1)$};

    node[black, above] at (24,24) {$(1,1)$};

    end{tikzpicture}%
    end{document}






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 16 at 9:32

























    answered Dec 16 at 9:13









    Peter Grill

    164k25434746




    164k25434746












    • Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
      – Aiden Kenny
      Dec 23 at 17:09










    • @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
      – Peter Grill
      Dec 23 at 17:58












    • @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
      – Peter Grill
      Dec 23 at 18:00


















    • Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
      – Aiden Kenny
      Dec 23 at 17:09










    • @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
      – Peter Grill
      Dec 23 at 17:58












    • @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
      – Peter Grill
      Dec 23 at 18:00
















    Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
    – Aiden Kenny
    Dec 23 at 17:09




    Just curious, for using pgfplotsinvokeforeach, the resulting drawing is what I want, but I get the error message: "Illegal parameter number in definition of test". It then says "You meant to type ## instead of #, right?" Do you have any idea why this is happening?
    – Aiden Kenny
    Dec 23 at 17:09












    @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
    – Peter Grill
    Dec 23 at 17:58






    @AidenKenny: I am guessng that you are using pgfplotsinvokeforeach within a macro where #1 refers to the first parameter of the macro. Thus, if you are using pgfplotsinvokeforeach within a macro definition, you need to use ##1 to refer to the parameters of the pgfplotsinvokeforeach. This is similar to the issue with defening a macro within a macro: where #1 would refer to the first parameter of the outer macro and ##1 would refe to the first parameter of the inner macro.
    – Peter Grill
    Dec 23 at 17:58














    @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
    – Peter Grill
    Dec 23 at 18:00




    @AidenKenny: If that does not solve your issue, please ask a new question with a MWE including documentclass that reproduces the problem.
    – Peter Grill
    Dec 23 at 18:00











    6














    Two other options without pgfplots, one without foreach and one with foreach:



    documentclass[tikz,border=2mm]{standalone} 
    usetikzlibrary{positioning}

    begin{document}
    begin{tikzpicture}
    draw (0,0) grid (24,24);
    node[above right] at (24,24) {$(1,1)$};
    node[above left] at (0,24) {$(0,1)$};
    node[below left] at (0,0) {$(0,0)$};
    node[below right] at (24,0) {$(1,0)$};
    end{tikzpicture}

    begin{tikzpicture}
    foreach i in {0,...,24}{
    draw (i,0) -- ++(90:24);
    draw (0,i) -- ++(0:24);
    }
    node[above right] at (24,24) {$(1,1)$};
    node[above left] at (0,24) {$(0,1)$};
    node[below left] at (0,0) {$(0,0)$};
    node[below right] at (24,0) {$(1,0)$};
    end{tikzpicture}

    end{document}


    enter image description here






    share|improve this answer


























      6














      Two other options without pgfplots, one without foreach and one with foreach:



      documentclass[tikz,border=2mm]{standalone} 
      usetikzlibrary{positioning}

      begin{document}
      begin{tikzpicture}
      draw (0,0) grid (24,24);
      node[above right] at (24,24) {$(1,1)$};
      node[above left] at (0,24) {$(0,1)$};
      node[below left] at (0,0) {$(0,0)$};
      node[below right] at (24,0) {$(1,0)$};
      end{tikzpicture}

      begin{tikzpicture}
      foreach i in {0,...,24}{
      draw (i,0) -- ++(90:24);
      draw (0,i) -- ++(0:24);
      }
      node[above right] at (24,24) {$(1,1)$};
      node[above left] at (0,24) {$(0,1)$};
      node[below left] at (0,0) {$(0,0)$};
      node[below right] at (24,0) {$(1,0)$};
      end{tikzpicture}

      end{document}


      enter image description here






      share|improve this answer
























        6












        6








        6






        Two other options without pgfplots, one without foreach and one with foreach:



        documentclass[tikz,border=2mm]{standalone} 
        usetikzlibrary{positioning}

        begin{document}
        begin{tikzpicture}
        draw (0,0) grid (24,24);
        node[above right] at (24,24) {$(1,1)$};
        node[above left] at (0,24) {$(0,1)$};
        node[below left] at (0,0) {$(0,0)$};
        node[below right] at (24,0) {$(1,0)$};
        end{tikzpicture}

        begin{tikzpicture}
        foreach i in {0,...,24}{
        draw (i,0) -- ++(90:24);
        draw (0,i) -- ++(0:24);
        }
        node[above right] at (24,24) {$(1,1)$};
        node[above left] at (0,24) {$(0,1)$};
        node[below left] at (0,0) {$(0,0)$};
        node[below right] at (24,0) {$(1,0)$};
        end{tikzpicture}

        end{document}


        enter image description here






        share|improve this answer












        Two other options without pgfplots, one without foreach and one with foreach:



        documentclass[tikz,border=2mm]{standalone} 
        usetikzlibrary{positioning}

        begin{document}
        begin{tikzpicture}
        draw (0,0) grid (24,24);
        node[above right] at (24,24) {$(1,1)$};
        node[above left] at (0,24) {$(0,1)$};
        node[below left] at (0,0) {$(0,0)$};
        node[below right] at (24,0) {$(1,0)$};
        end{tikzpicture}

        begin{tikzpicture}
        foreach i in {0,...,24}{
        draw (i,0) -- ++(90:24);
        draw (0,i) -- ++(0:24);
        }
        node[above right] at (24,24) {$(1,1)$};
        node[above left] at (0,24) {$(0,1)$};
        node[below left] at (0,0) {$(0,0)$};
        node[below right] at (24,0) {$(1,0)$};
        end{tikzpicture}

        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 16 at 9:18









        Ignasi

        91.5k4165303




        91.5k4165303






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f466054%2fdrawing-grid-lines-using-foreach%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

            Morgemoulin

            Scott Moir

            Souastre