What is wrong with my foreach statement The Next CEO of Stack OverflowPGFplots foreach equivalent to TikZ's with multiple variables separated by a slashforeach with indexed names of curvesTikz: foreach and axis environment incompatibilityTikz externalize and placing a caption overlapping with a picturepgfplots: multiple loops for ticks, positioning, etcIssue with foreach statementWhat is wrong with this foreach statement?Issue with trigonometric ratios in foreach statementTikz, graphdrawing: How to use foreach variables to set edge node labels?pgfplots: modify axis after end axis / cut tikzpicture after drawingExpand Tikz matrix with foreach statement?

Solving system of ODEs with extra parameter

Is micro rebar a better way to reinforce concrete than rebar?

The exact meaning of 'Mom made me a sandwich'

Would be okay to drive on this tire?

Is there always a complete, orthogonal set of unitary matrices?

Why is quantifier elimination desirable for a given theory?

Is a distribution that is normal, but highly skewed considered Gaussian?

Chain wire methods together in Lightning Web Components

Find non-case sensitive string in a mixed list of elements?

Why is information "lost" when it got into a black hole?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

How to get from Geneva Airport to Metabief, Doubs, France by public transport?

Does increasing your ability score affect your main stat?

Can you be charged for obstruction for refusing to answer questions?

RigExpert AA-35 - Interpreting The Information

Should I tutor a student who I know has cheated on their homework?

Why is my new battery behaving weirdly?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

Unclear about dynamic binding

Won the lottery - how do I keep the money?

Is it okay to majorly distort historical facts while writing a fiction story?

Grabbing quick drinks

Axiom Schema vs Axiom



What is wrong with my foreach statement



The Next CEO of Stack OverflowPGFplots foreach equivalent to TikZ's with multiple variables separated by a slashforeach with indexed names of curvesTikz: foreach and axis environment incompatibilityTikz externalize and placing a caption overlapping with a picturepgfplots: multiple loops for ticks, positioning, etcIssue with foreach statementWhat is wrong with this foreach statement?Issue with trigonometric ratios in foreach statementTikz, graphdrawing: How to use foreach variables to set edge node labels?pgfplots: modify axis after end axis / cut tikzpicture after drawingExpand Tikz matrix with foreach statement?










1















The code below works fine



begintikzpicture
beginaxis
[
ticks = none, axis lines = middle,
xmin = -5, xmax = 5,
ymin = -5, ymax = 5,
]
foreach p in 1,2
draw[red] (-5,1)--(5,1);

endaxis
endtikzpicture


However, as soon as I try to use the variable p inside the loop, as in



begintikzpicture
beginaxis
[
ticks = none, axis lines = middle,
xmin = -5, xmax = 5,
ymin = -5, ymax = 5,
]
foreach p in 1,2
draw[red] (-5,p)--(5,p);

endaxis
endtikzpicture


I get an undefined control sequence error. This persists no matter what I use instead of p.










share|improve this question







New contributor




Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    1















    The code below works fine



    begintikzpicture
    beginaxis
    [
    ticks = none, axis lines = middle,
    xmin = -5, xmax = 5,
    ymin = -5, ymax = 5,
    ]
    foreach p in 1,2
    draw[red] (-5,1)--(5,1);

    endaxis
    endtikzpicture


    However, as soon as I try to use the variable p inside the loop, as in



    begintikzpicture
    beginaxis
    [
    ticks = none, axis lines = middle,
    xmin = -5, xmax = 5,
    ymin = -5, ymax = 5,
    ]
    foreach p in 1,2
    draw[red] (-5,p)--(5,p);

    endaxis
    endtikzpicture


    I get an undefined control sequence error. This persists no matter what I use instead of p.










    share|improve this question







    New contributor




    Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      1












      1








      1


      0






      The code below works fine



      begintikzpicture
      beginaxis
      [
      ticks = none, axis lines = middle,
      xmin = -5, xmax = 5,
      ymin = -5, ymax = 5,
      ]
      foreach p in 1,2
      draw[red] (-5,1)--(5,1);

      endaxis
      endtikzpicture


      However, as soon as I try to use the variable p inside the loop, as in



      begintikzpicture
      beginaxis
      [
      ticks = none, axis lines = middle,
      xmin = -5, xmax = 5,
      ymin = -5, ymax = 5,
      ]
      foreach p in 1,2
      draw[red] (-5,p)--(5,p);

      endaxis
      endtikzpicture


      I get an undefined control sequence error. This persists no matter what I use instead of p.










      share|improve this question







      New contributor




      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      The code below works fine



      begintikzpicture
      beginaxis
      [
      ticks = none, axis lines = middle,
      xmin = -5, xmax = 5,
      ymin = -5, ymax = 5,
      ]
      foreach p in 1,2
      draw[red] (-5,1)--(5,1);

      endaxis
      endtikzpicture


      However, as soon as I try to use the variable p inside the loop, as in



      begintikzpicture
      beginaxis
      [
      ticks = none, axis lines = middle,
      xmin = -5, xmax = 5,
      ymin = -5, ymax = 5,
      ]
      foreach p in 1,2
      draw[red] (-5,p)--(5,p);

      endaxis
      endtikzpicture


      I get an undefined control sequence error. This persists no matter what I use instead of p.







      tikz-pgf loops






      share|improve this question







      New contributor




      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 7 hours ago









      MrahtaMrahta

      61




      61




      New contributor




      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Mrahta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Welcome to TeX-SE! Notice that pgfplots does a lot of service in the background, which is why some variantes of foreach may not work in an axis environment. These things are explained in detail in section 8.1 Utility Commands of the pgfplots manual. Long story short for this case: use pgfplotsinvokeforeach instead.



          documentclass[tikz,border=3.14mm]standalone
          usepackagepgfplots
          pgfplotssetcompat=1.16
          begindocument
          begintikzpicture
          beginaxis
          [
          ticks = none, axis lines = middle,
          xmin = -5, xmax = 5,
          ymin = -5, ymax = 5,
          ]
          pgfplotsinvokeforeach1,2
          draw[red] (-5,#1)--(5,#1);

          endaxis
          endtikzpicture
          enddocument


          enter image description here



          There are situations in which you really want to use the traditional foreach loop. In those you can you can use this answer to get



          documentclass[tikz,border=3.14mm]standalone
          usepackagepgfplots
          pgfplotssetcompat=1.16
          begindocument
          begintikzpicture
          beginaxis
          [
          ticks = none, axis lines = middle,
          xmin = -5, xmax = 5,
          ymin = -5, ymax = 5,
          ]
          foreach p in 1,2
          edeftempnoexpanddraw[red] (-5,p)--(5,p);
          temp

          endaxis
          endtikzpicture
          enddocument


          Side-remark: try to avoid calling the loop variable p, n, x or y if you consider making use of the calc library because there these macros have their own meanings.






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



            );






            Mrahta is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482311%2fwhat-is-wrong-with-my-foreach-statement%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Welcome to TeX-SE! Notice that pgfplots does a lot of service in the background, which is why some variantes of foreach may not work in an axis environment. These things are explained in detail in section 8.1 Utility Commands of the pgfplots manual. Long story short for this case: use pgfplotsinvokeforeach instead.



            documentclass[tikz,border=3.14mm]standalone
            usepackagepgfplots
            pgfplotssetcompat=1.16
            begindocument
            begintikzpicture
            beginaxis
            [
            ticks = none, axis lines = middle,
            xmin = -5, xmax = 5,
            ymin = -5, ymax = 5,
            ]
            pgfplotsinvokeforeach1,2
            draw[red] (-5,#1)--(5,#1);

            endaxis
            endtikzpicture
            enddocument


            enter image description here



            There are situations in which you really want to use the traditional foreach loop. In those you can you can use this answer to get



            documentclass[tikz,border=3.14mm]standalone
            usepackagepgfplots
            pgfplotssetcompat=1.16
            begindocument
            begintikzpicture
            beginaxis
            [
            ticks = none, axis lines = middle,
            xmin = -5, xmax = 5,
            ymin = -5, ymax = 5,
            ]
            foreach p in 1,2
            edeftempnoexpanddraw[red] (-5,p)--(5,p);
            temp

            endaxis
            endtikzpicture
            enddocument


            Side-remark: try to avoid calling the loop variable p, n, x or y if you consider making use of the calc library because there these macros have their own meanings.






            share|improve this answer





























              1














              Welcome to TeX-SE! Notice that pgfplots does a lot of service in the background, which is why some variantes of foreach may not work in an axis environment. These things are explained in detail in section 8.1 Utility Commands of the pgfplots manual. Long story short for this case: use pgfplotsinvokeforeach instead.



              documentclass[tikz,border=3.14mm]standalone
              usepackagepgfplots
              pgfplotssetcompat=1.16
              begindocument
              begintikzpicture
              beginaxis
              [
              ticks = none, axis lines = middle,
              xmin = -5, xmax = 5,
              ymin = -5, ymax = 5,
              ]
              pgfplotsinvokeforeach1,2
              draw[red] (-5,#1)--(5,#1);

              endaxis
              endtikzpicture
              enddocument


              enter image description here



              There are situations in which you really want to use the traditional foreach loop. In those you can you can use this answer to get



              documentclass[tikz,border=3.14mm]standalone
              usepackagepgfplots
              pgfplotssetcompat=1.16
              begindocument
              begintikzpicture
              beginaxis
              [
              ticks = none, axis lines = middle,
              xmin = -5, xmax = 5,
              ymin = -5, ymax = 5,
              ]
              foreach p in 1,2
              edeftempnoexpanddraw[red] (-5,p)--(5,p);
              temp

              endaxis
              endtikzpicture
              enddocument


              Side-remark: try to avoid calling the loop variable p, n, x or y if you consider making use of the calc library because there these macros have their own meanings.






              share|improve this answer



























                1












                1








                1







                Welcome to TeX-SE! Notice that pgfplots does a lot of service in the background, which is why some variantes of foreach may not work in an axis environment. These things are explained in detail in section 8.1 Utility Commands of the pgfplots manual. Long story short for this case: use pgfplotsinvokeforeach instead.



                documentclass[tikz,border=3.14mm]standalone
                usepackagepgfplots
                pgfplotssetcompat=1.16
                begindocument
                begintikzpicture
                beginaxis
                [
                ticks = none, axis lines = middle,
                xmin = -5, xmax = 5,
                ymin = -5, ymax = 5,
                ]
                pgfplotsinvokeforeach1,2
                draw[red] (-5,#1)--(5,#1);

                endaxis
                endtikzpicture
                enddocument


                enter image description here



                There are situations in which you really want to use the traditional foreach loop. In those you can you can use this answer to get



                documentclass[tikz,border=3.14mm]standalone
                usepackagepgfplots
                pgfplotssetcompat=1.16
                begindocument
                begintikzpicture
                beginaxis
                [
                ticks = none, axis lines = middle,
                xmin = -5, xmax = 5,
                ymin = -5, ymax = 5,
                ]
                foreach p in 1,2
                edeftempnoexpanddraw[red] (-5,p)--(5,p);
                temp

                endaxis
                endtikzpicture
                enddocument


                Side-remark: try to avoid calling the loop variable p, n, x or y if you consider making use of the calc library because there these macros have their own meanings.






                share|improve this answer















                Welcome to TeX-SE! Notice that pgfplots does a lot of service in the background, which is why some variantes of foreach may not work in an axis environment. These things are explained in detail in section 8.1 Utility Commands of the pgfplots manual. Long story short for this case: use pgfplotsinvokeforeach instead.



                documentclass[tikz,border=3.14mm]standalone
                usepackagepgfplots
                pgfplotssetcompat=1.16
                begindocument
                begintikzpicture
                beginaxis
                [
                ticks = none, axis lines = middle,
                xmin = -5, xmax = 5,
                ymin = -5, ymax = 5,
                ]
                pgfplotsinvokeforeach1,2
                draw[red] (-5,#1)--(5,#1);

                endaxis
                endtikzpicture
                enddocument


                enter image description here



                There are situations in which you really want to use the traditional foreach loop. In those you can you can use this answer to get



                documentclass[tikz,border=3.14mm]standalone
                usepackagepgfplots
                pgfplotssetcompat=1.16
                begindocument
                begintikzpicture
                beginaxis
                [
                ticks = none, axis lines = middle,
                xmin = -5, xmax = 5,
                ymin = -5, ymax = 5,
                ]
                foreach p in 1,2
                edeftempnoexpanddraw[red] (-5,p)--(5,p);
                temp

                endaxis
                endtikzpicture
                enddocument


                Side-remark: try to avoid calling the loop variable p, n, x or y if you consider making use of the calc library because there these macros have their own meanings.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 7 hours ago

























                answered 7 hours ago









                marmotmarmot

                113k5145274




                113k5145274




















                    Mrahta is a new contributor. Be nice, and check out our Code of Conduct.









                    draft saved

                    draft discarded


















                    Mrahta is a new contributor. Be nice, and check out our Code of Conduct.












                    Mrahta is a new contributor. Be nice, and check out our Code of Conduct.











                    Mrahta is a new contributor. Be nice, and check out our Code of Conduct.














                    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%2f482311%2fwhat-is-wrong-with-my-foreach-statement%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

                    Wikipedia:Contact us Navigation menu Navigation menuLeave a Reply Cancel reply Post navigationRecent PostsRecent CommentsArchivesCategoriesMeta

                    Farafra Inhaltsverzeichnis Geschichte | Badr-Museum Farafra | Nationalpark Weiße Wüste (as-Sahra al-baida) | Literatur | Weblinks | Navigationsmenü27° 3′ N, 27° 58′ OCommons: Farafra

                    Tórshavn Kliima | Partnerstääden | Luke uk diar | Nawigatsjuun62° 1′ N, 6° 46′ W62° 1′ 0″ N, 6° 46′ 0″ WWMOTórshavn