Questions tagged [foreach]

{foreach} is for questions regarding the TikZ/PGF module of the same name which can also be used as a standalone package pgffor.

Filter by
Sorted by
Tagged with
0
votes
0answers
11 views

How to use macro as a `foreach` range? [duplicate]

These two loops do not produce the same result: \documentclass{article} \usepackage{tikz} \begin{document} \foreach \i in {a,b,c} {% \i+ } \def\Index{a,b,c} \foreach \i in {\Index} {% \i+ ...
7
votes
1answer
141 views

Plotting curves within a foreach loop and attributing colors from a colormap

I'm trying to plot curves inside a \foreach loop and at the same time define their color through a colormap. The color is given accordingly to a parameter of the curve:(\T/\Tmax*1000), where \T is the ...
0
votes
1answer
30 views

Use \foreach within animate inline in Beamer class throws error

I encounter an issue with the following code and must admit that I was able to find trick on the forum for now. \begin{frame}{Title} \begin{figure}[htbp] \begin{center} \begin{animateinline}[loop,...
2
votes
3answers
39 views

smallcaps in a matrix, \\ coupled with foreach loop

I wanted to make a command which would put all of my text in smallcaps and in a matrix. This is \fmold below. This gave me an error, prompting me to make a foreach loop as seen in \smallcapsify and \...
1
vote
0answers
16 views

pgfplots: Exemplary comparison and differences between \foreach, \pgfplotsforeachungrouped, and \pgfplotsinvokeforeach

My previous question made me take a look at pgfplots manual to understand the differences between \foreach and \pgfplotsinvokeforeach. However, the examples are not enough to comprehensively ...
4
votes
1answer
46 views

pgfplots: How to iterate over plot styles using foreach?

For the following, the variable \mystyle doesn't work as expected. Therefore, how can I: 1- optimize the code by making three lists of values of \myalph, \mystyle, and \mylabel to be iterated over ...
4
votes
3answers
141 views

Problem when including a foreach loop

I have the next code which makes exacty what I wanted, that is, to plot the triangle and show the values of every interior angle. \documentclass{standalone} \usepackage{tikz}\usetikzlibrary{angles,...
6
votes
3answers
230 views

How do I get a decreased-by-one \x in a foreach loop?

My problem is pretty much complicated than this one, but the point is pretty similar. \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \coordinate (A1) at (0,0); \...
0
votes
1answer
49 views

Positioning 2 \foreach loops in 2 different locations

Using the following code from the answer to this question \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{verbatim} \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{...
1
vote
2answers
71 views

Combining 2 \foreach loops into one

Using the following code (from the answer to this question) to draw boxes using 2 \foreach loops; and defining the starting positions of both of them (yshift=.4cm and yshift=4.4cm). I want the blue ...
2
votes
2answers
61 views

Linking a \foreach loop to start from a specific node position

Using the following code, I manually have made the \foreach loop starts from the location of the center of node B. How can I automatically start the \foreach loop at the center of node B, so that ...
1
vote
1answer
59 views

Change related to \foreach \x[remember=\x as \MyLastx] in TeXLive2019

I just recently upgraded to TeXLive2019 and the code below fails to compile in TeXLive2019 with the message Undefined control sequence. <argument> \MyLastx But compiles fine in TeXLive2018. ...
0
votes
1answer
46 views

foreach loop in tikz and math mode

Here is what I want to do: \begin{tikzpicture} \foreach \i in {1,...,8} \foreach \j in {1,...,8} \foreach \t in {1,2,3}{ \node () at (\i,\t,\j) {$X_{\i,\j,\t}$}; } \end{...
5
votes
2answers
128 views

Tikz - Coordinates error when using draw with axis

I am using the following code, which is supposed to cut a function in N parts : \documentclass[11pt]{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} ...
1
vote
1answer
43 views

Drawing a number line

I am going through the TikZ tutorial in the manual, and I am trying to make my own examples. However, I cannot understand why my code is not woking as intended. I would like to draw a number line, ...
2
votes
2answers
89 views

using '\foreach' loops to draw tikz figures

I am using \usepackage{tikz} to draw something using xyz coordinates. I have a bunch of coordinates named (xyt) such as (000) (001) (020)...(001)(011) etc, they are created by: \coordinate (ijk) at (...
1
vote
1answer
34 views

Foreach and different color compilation error

if you execute this code there will be a compilation error, but if you replace red!\rnb!blue by red!20!blue it works fine. \documentclass[border=2pt]{standalone} \usepackage[utf8]{inputenc} ...
4
votes
1answer
56 views

foreach in pgfplots

I want to plot a series of functions, each in another color. I would like to do this with a foreach, but it doesn't work. First I try a simple tikzpicture (from another mwe), this works. Then the ...
4
votes
2answers
141 views

Use evaluate option of \foreach to display integers not floats in TikZ

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[->] (-2,0) -- (2,0) node[right] {$x$}; \draw[->] (0,-2) -- (0,2) node[above] {$y$}; \...
2
votes
1answer
58 views

How to draw an arrow circle at a certain coordinate?

I defined an arrow circle but I do not know, how to move it to a specified coordinate. Code: \begin{tikzpicture} \foreach \x in {0,30,...,360} \draw[<-] (\x:0.35cm) -- (\x:0.7cm); \end{...
6
votes
3answers
144 views

Basic calculations in PGF/TikZ for loop

I've seen a bunch of similar questions and answers relating to the same kind of problem, but they either weren't particularly well explained or something got lost in translation somewhere. So I ...
0
votes
2answers
74 views

Problem with \foreach in Tikz

I'm using \foreach in Tikz to make a line with vertical marks at some real numbers. But I want to put \pi and \e (Euler number) in the code, but it doesnt work. Please, can anyone help me? My Code: ...
1
vote
1answer
42 views

Problem with tikz foreach with veclen

I tried to draw a poly-line based on a list of coordinates but with the code below the starting points of each segment of the line are shifted to the right and the calculation of the length with ...
2
votes
1answer
38 views

Define and use paths inside foreach

I've looked at this and that, and I'm unable to compile and use intersections of lines i give name inside the same foreach loop. \documentclass[tikz]{standalone} \usepackage{tikz} \usetikzlibrary{...
0
votes
0answers
35 views

foreach looping error [duplicate]

Prior to posting this question, I have read the post here: OP asks the same question two or three times or does the same strange things several times My purpose in asking same questions with ...
2
votes
1answer
91 views

foreach loop error in generating diagrams

In my previous question, How to set macro for looping with minipage?, I was suggested using a foreach loop to solve the problem. After testing, the loop works correctly as show in page 1 pdf. However, ...
3
votes
0answers
53 views

Doing iterative arithmetic inside of an iterative tabularx

I'm trying to create a matrix table that will iteratively fill in the cells based on inputs that I can change. I originally tried the solution shown here, but I wasn't able to get Latex to properly ...
10
votes
3answers
233 views

Smart-expansion of a range to a list of numbers

I am wondering if there is a simple way to expand some input text such as "3-7" as "3,4,5,6,7"? For context, I am using \foreach and want to be able to write \foreach \x in {3-7, 9, 14, 52} and ...
3
votes
2answers
85 views

Passing optional arguments to \printbibliography as variables

title and keyword are optional arguments to the Biblatex command, printbibliography. Is it possible to pass a title and keyword as variables to printbibliography? The use case is the production of a ...
9
votes
1answer
222 views

Why does a perfectly-identical repetition of a drawing command given within an earlier loop 𝘯𝘰𝘵 produce exactly the same line?

Question. Why does the following code produce a line from vertex 0 to vertex 1 which does not perfectly coincide with the analogous line drawn earlier (by way of the foreach-loop)? \begin{...
0
votes
1answer
42 views

Tikz \foreach to work with the aligned environment

I am trying to use the \foreach command to create something with the same effect as: \begin{align*} 1 \\ 2 \end{align*} The following code fails to work: \begin{align*} \foreach \x in {1,2} ...
2
votes
1answer
54 views

Making a checkerboard with `foreach`

Why are these two diagrams different? \documentclass{amsart} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{tikz} \usetikzlibrary{calc,intersections} \begin{document} \begin{tikzpicture} \...
2
votes
2answers
46 views

If clause within a loop

I have a similar issue as the one discussed here If condition controlled with a loop variable. To summarize my case: when looping through a continous range of numbers, from 1 to 24, I'd like do ...
6
votes
5answers
315 views

Nested loops to process groups of pictures

The following MWE processes groups of pictures, placing them on a slide with a caption below the picture. The slides are made using the pdfscreen package, and the picture and caption placement is done ...
2
votes
1answer
34 views

Place node in the middle on an arc during a foreach statement

This question is akin to this one, The difference being that I want to place my nodes during a foreach loop. MWE: \documentclass[border=5pt,tikz]{standalone} \usepackage[utf8]{inputenc} \usepackage[...
2
votes
1answer
25 views

using two `\foreach` variables multiplied to select a color mixture

I'm trying to draw a grid with a mix of colors, that changes depending both on the x and y coordinate (MWE): \documentclass[border=4pt]{standalone} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}...
3
votes
2answers
63 views

Filling (continuous) Path using \foreach with complex calculations for each point

I am trying to draw a curve by calculating every point's position in a \foreach loop (potentially hundreds of points). Since the calculation is quite complex, I use \pgfmathsetmacro multiple times to ...
3
votes
1answer
30 views

Specifying coordinates in tikzcd arrows with a foreach loop

I'm trying to use a foreach loop to draw a whole bunch of arrows in a tikzcd environment by using the foreach loop to specify coordinates but I can't get it to compile. Here's a minimal example of ...
1
vote
1answer
82 views

Populating a tikz matrix with complex content

I am trying to populate a tikz matrix dynamically using foreach to loop over a list-argument and breaking it further apart using xstring operations. I am hitting an issue where, as far as I can tell, ...
1
vote
1answer
39 views

looping through with a function to generate coordinates for PGFPlots graph

Is there a way to loop through with a function in pgfplots to generate a set of coordinates? So far I've done the manual way of just inputting values, but this will quickly get tedious as I want to ...
1
vote
1answer
23 views

\foreach iterates through list as one argument? - Help please

My question is very simple. The following lines \documentclass[10pt,german]{article} \usepackage[T1]{fontenc} \usepackage[ngerman]{babel} \usepackage{pgffor} %foreach \expandafter\xdef\csname ...
1
vote
2answers
114 views

How to place nodes around a circle from some initial angle?

The code below generates 6 nodes placed around a circle at angles 60, 120, 180, ..., 360 with labels 1, 2, 3, ..., 6, respectively. However, I would like to place these 6 nodes in the way (where the ...
1
vote
2answers
66 views

foreach / pgfmath: create a list of specific values

I would need a list, possibly an array (for later use in a foreach loop / TikZ graphic), which contains the following values ​​(a_n) in order (n = 1,2,3, ...): 45,135,225,270,315, 45,45,90,135,135,...
6
votes
2answers
591 views

First index is not integer using foreach loop from 0

I am trying to draw a tree using tikzpicture like this: \documentclass{article} \usepackage{tikz} \usetikzlibrary{math} \begin{document} \begin{tikzpicture} \tikzstyle{node}=[circle, fill=blue!25,...
1
vote
1answer
36 views

Create command that uses a \foreach to be used in a barycentric cs

I'm trying create a command that will be used in a barycentric cs:. I will use the barycentric cs a lot of time to get a node the middle of others, so I'm trying to make it less painfull for myself. ...
0
votes
1answer
46 views

Newcommand that uncludes a foreach with unknown number of parameters

Sorry, but part of the code is in French. However, it won't matter because it's only the listed text I currently have a new command named \listerfe that, combined with \listerfenextarg and \...
3
votes
2answers
152 views

"Illegal unit of measure (pt inserted)” Problem with foreach

I'm trying to make a series of circles with gradients. On the second page, which is created, there is only /2pt/1pt/2pt and on the last /20pt. I guess there's something wrong with my foreach loop, but ...
6
votes
1answer
217 views

Using for loop in tikz to draw repeated shapes

I am trying to create a lenticular pattern like the one in the picture. I believe the repeated shape can be drawn using a for loop in tikz, but I wasn't able to get it done properly. Appreciate any ...
2
votes
1answer
60 views

Generating TikZ Nodes and Labels from Custom Array Strings

I am trying to use the TikZ environment to annotate a graphic with labels in multiple specific locations. Instead of repeating the node command many times and changing the node location and label, I ...
1
vote
1answer
60 views

Tikz, foreach, evaluate and \ifodd combination yields “Use of \@next does not match it's definition”

I'm trying to run this. \documentclass[tikz,border=5mm]{standalone} \begin{document} \begin{tikzpicture} \draw\foreach \s [evaluate=\s as \lowhigh using \s+1] in {1,...,4}{ \ifodd\...