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?
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
tikz-pgf loops
New contributor
New contributor
New contributor
asked 7 hours ago
MrahtaMrahta
61
61
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Mrahta is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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
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
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.
add a comment |
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
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.
add a comment |
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
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.
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
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.
edited 7 hours ago
answered 7 hours ago
marmotmarmot
113k5145274
113k5145274
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482311%2fwhat-is-wrong-with-my-foreach-statement%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown