Skip to main content

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
1 vote
2 answers
68 views

How to create a command to plot a series of square lattices on a given line?

As the figure below, for a fixed line on a square-lattice layer with the scale of 30*30, it y-coordinate is 12, then I'd like to plot squares on the x-coordinates of 1,6-13,21,28-30, 13 square dots in ...
Meiu's user avatar
  • 548
0 votes
1 answer
25 views

Displaying table content within a pgfplot [duplicate]

I've got a table with a binary column named xrayOn. Instead of plotting this, I want to write each xrayOn value (i.e. 0 or 1) at the position (index, 1) in a node. However, in the code below only the ...
luwi's user avatar
  • 13
0 votes
2 answers
53 views

Fuzzy Number Line

I'm trying to create a command that generates a number line for an arithmetic progression. For example \SNL{10}{5}{9} generates a number line with the first value of 10, common difference of 5 and ...
Wendy Taylor's user avatar
2 votes
2 answers
73 views

Polynomial long division with macro command in a for loop (to get different coefficients)

I would like to create problem sheets with polynomial long division, where each student gets different polynomials. I tried to use the polynom package, but the following code does not compile (it does ...
Watson's user avatar
  • 984
3 votes
3 answers
267 views

List of numbers in an arithmetic progression

I need to generate a list of numbers in an arithmetic progression. For example 3,7,11,15,19. I was hopeful there was a way to achieve this by specifying the first term (a), the common difference (d) ...
Wendy Taylor's user avatar
1 vote
3 answers
52 views

Infinite loop in foreach in pgfplots axis?

I'm trying to generate a staircase plot by computing the coordinates with a foreach loop, but the compilation never stops and gives nothing. A minimal example follows: \documentclass{article} \...
vonbrand's user avatar
  • 5,551
2 votes
1 answer
84 views

Print macro in \addplot node label

I use a foreach loop to plot multiple curves via the \addplot command. The values that are necessary to define the relevant curve in each iteration are defined through some macros with the command \...
Laura Roich's user avatar
2 votes
1 answer
53 views

Fill area under curve points

So, I have this code and I need to fill area under curve points. How can I do that? a) First, I need to fill area under curve points from x = 1 to x = 5 b) I need to complete fill area. Thanks. \...
Pedro Salgado's user avatar
1 vote
1 answer
71 views

Draw arrow between two points in a list in TikZ

I am trying to connect a set of dots with arrows using tkiz. I am trying to demonstrate the motion of something as a function of time with the arrow indicating the motion. I can get the dots where I ...
msntechguy's user avatar
0 votes
0 answers
34 views

Creating a yearly training log with calendar.sty and loops

I'm quite new to LaTeX and just playing around learning new things. So i want to create a PDF that i can print as a book to log my training and still be able to write some things with a pen. It should ...
Groggy's user avatar
  • 1
2 votes
1 answer
65 views

pgf list with length registers

Is it possible in tikz to generate a list using length registers? for exemple: \foreach \x in {0,1,...,6} with produce the following list: "0,1,2,3,4,5,6" but now I want to produce a list ...
user1850133's user avatar
  • 1,028
1 vote
1 answer
47 views

`foreach` does not work together with `ifthenelse` and `mod`

In the minimal example below, the commented out line does not work. Other lines work correctly. I can't understand what the reason is. Here is a similar question, but my variable \im takes integer ...
kabenyuk's user avatar
  • 616
2 votes
4 answers
110 views

Loop to input content into tabular

I'm trying to input files that represent rows of a table into a tabular environment using a loop, but I'm having trouble using input. Here is a MWE of my code without using loops. I have files with ...
Nicolas Suarez's user avatar
2 votes
2 answers
115 views

How to pass an argument to a macro called with \csname

I have a macro that generates lists of random numbers and converts them into letters to print. I'd like to create another macro that prints those lists with intervening text. That is, if \first ...
CBaker's user avatar
  • 23
2 votes
0 answers
62 views

pgfplots: find the intersection point of two curves and determine the y value of the intersection point

Thank you for reading my question! Introduction Now I want to draw a picture, in which I need to calculate the intersection point of the two curves and determine whether the y value of the ...
BqBPdx's user avatar
  • 39
0 votes
1 answer
131 views

Repeating drawing isosceles triangle

From the answer to this question, I would like to add repeated circles, rectangles, and isosceles triangles. I applied this code to draw the following figure, but I could not use \foreach to repeat ...
Hany's user avatar
  • 4,927
2 votes
1 answer
57 views

Use foreach count index as variable in pgfplots

I have a beamer frame with an axis environment that contains a foreach loop. I would like to use the count index deriving from such loop as a variable within the loop. Specifically, I need such ...
Laura Roich's user avatar
1 vote
1 answer
43 views

Doubt about \pgfplotsinvokeforeach

I was using tikz and I had a problem using \draw[] inside a \foreach loop, so I found \pgfplotsinvokeforeach and I have doubts about how it works. This is an example \documentclass{article} \...
Michael Rosales Vilca's user avatar
4 votes
2 answers
287 views

How to use \foreach and \newtheorem together?

I want to use \foreach and newtheorem together, so I've assigned an array with the package listofitems \setsepchar{;/,}\ignoreemptyitems \readlist\baz { theorem, lemma, definition, corollary, ...
Meiu's user avatar
  • 548
1 vote
1 answer
49 views

Getting overlapping circles (or any shapes) along a closed curve in tikz

I have been trying to figure out how I can have overlapping circles along the path of a closed curve. I have seen that if I use the Bezier curve commands, then I can almost kind of get what I'm ...
CyCeez's user avatar
  • 23
0 votes
1 answer
55 views

Rectangle Split in tikz Node using Loop Statement

I want to dynamically loop through the Instruction Fields so as to draw the register containing them. The code I came up with is the following: \documentclass{standalone} \usepackage{amsmath} \...
Alexander Tsagkaropoulos's user avatar
1 vote
0 answers
15 views

saving computed values in a file or table from a foreach loop in a regression plot

I want to save the regression slopes of those data sets for a further table. I manage to add rows in a initial table in the foreach loop but adding the plots doesn't work anymore.... Thanks in advance ...
laurent's user avatar
  • 41
0 votes
0 answers
32 views

TikZ: collecting defined coordinates in a list

I want to collect previously defined coordinates in a list and print them later in a \foreach-loop for debugging purposes. The following MWE shows the list \points which ideally should be defined and ...
kaat0's user avatar
  • 1
1 vote
1 answer
57 views

Using foreach and cs coordinates, foreach evaluate and axis

I was trying to draw dots over a pgfplots axis using axis cs coordinates. This works just fine typing the coordinates by hand, but fails as soon as I try to use the value coming from a foreach ...
Cryme's user avatar
  • 803
1 vote
1 answer
73 views

Using the result of TikZ foreach evaluate

I was trying to display the value of an evaluated variable in a TikZ foreach loop on a very basic example (tweaked from https://tikz.dev/pgffor#pgf./pgf/foreach/evaluate), but somehow it fails. See ...
Cryme's user avatar
  • 803
0 votes
1 answer
75 views

Loop Through Array of Strings (Actually an Array of Array of Strings, e.g. `{{black, ab}, {white, cd}}`)

I'm drawing stones on a Go (game) board with SGF coordinates (which I only managed to do from the the help people gave me on this question) like this \drawStoneFromSgfCoords{ab}. However, there might ...
psygo's user avatar
  • 438
1 vote
1 answer
113 views

How to make a loop-generated table depending on the outcome of a calculation?

As a Dutch teacher my grading scale goes from 1,0 to 10,0. The calculation of the grade depends on three variables: the N-term; the score of the student; the total number of points for the exam. I ...
KenAdams's user avatar
  • 139
1 vote
1 answer
43 views

Iterating over list of lists?

Following up on Customized list of elements using etoolbox in particular, second solution: Is there a convenient way to iterate over any of those lists? Example: \documentclass{article} \usepackage{...
Holger Karl's user avatar
2 votes
1 answer
75 views

How to do length calculations with based on a `\foreach` array

I'm trying to improve the readability of my \drawHoshis macro by creating variables for the x and y coordinates, besides also running a calculation with a minus inside parentheses (e.g. x * (y - 1)). ...
psygo's user avatar
  • 438
5 votes
2 answers
196 views

Change position within a tikz picture

I've been working on some code to support young children with their counting. A rectangle grid with some dots in it is called a tens frame The above image is the tens frame for 3. I am wanting ...
Wendy Taylor's user avatar
2 votes
1 answer
54 views

Define foreach step dynamically by arithmetic computations

Consider the following: \newcommand{\numA}{4} \foreach \j in {\numA,8,...,50}{...} As expected, \j will be 4,8,12,... and so on. Now, my question is: how to automatically set the second value as 2*\...
Sigur's user avatar
  • 37.5k
0 votes
1 answer
40 views

Numbering nodes based on calculation in a for loop

This may be one duplicate of this QA. But I failed to use its answer. Here is my example code: \documentclass{article} \usepackage{tikz} \usepackage{fp} \newcommand*{\xMin}{0}% \newcommand*{\xMax}{4}%...
An5Drama's user avatar
  • 163
3 votes
3 answers
134 views

LaTeX gives error when looping in tabular environment [duplicate]

Package used: pgffor Function used from package: foreach Compiled with: latex the minimised document: \documentclass[a4paper]{article} \usepackage{pgffor} \begin{document} \def\colourNames{red, ...
Tibor's user avatar
  • 33
4 votes
2 answers
194 views

tikz \foreach (miss?) behaving

In the code below, I expected the 3 cases (commented out) to be fully equivalent. Unfortunately (for me) the 3rd one produces a straight line from coordinate (X) to coordinate (Y). I always thought ...
Frigeri's user avatar
  • 156
3 votes
1 answer
93 views

Get the output of foreach rather than foreach itself

I want to get the output of the following macro stored in a variable: \foreach \m in {1,...,9}{\csname h\m \endcsname}; I tried to do: \def\lkj{ \foreach \m in {1,...,9}{\csname h\m \endcsname}; } ...
name_to_display's user avatar
1 vote
1 answer
42 views

Anchors not working on foreach-generated node names: "Unknown operator `c' or `ce' (in '0.center')."

So I try to generate a tikzpicture for the Pascal Triangle. This is my code & result so far: \begin{figure} \centering \begin{tikzpicture} \foreach \n in {0,...,7}{ \foreach \k in {0,.....
Krokant17's user avatar
0 votes
2 answers
77 views

Iterate with forloop instead of foreach [closed]

I have this {C/4/a/n,D/4/b/n,E/4/c/n} This is how I iterate it with foreach: \foreach \x\y\w\z in {C/4/a/n,D/4/b/n,E/4/c/n} { \x - \y - \w - \z } But I need to do it with forloop. It is ...
Arturo Rodas's user avatar
2 votes
2 answers
251 views

Tikz and foreach

Here is a TikZ code. How improve it ? Thanks \documentclass{article} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{tikz} \begin{document} \begin{...
Clairon's user avatar
  • 407
1 vote
1 answer
78 views

How to uniformly distribute pics on a curve?

I want to create a path in the form of a Bezier curve and place pic figures evenly along the path. In this example, the pics are only placed between the last two points of my curve and they are not ...
krysttof's user avatar
4 votes
1 answer
80 views

colours in loops [duplicate]

How can I get the following by a loop? \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[fill=green!20!black] (0,0) rectangle (1,1); \draw[fill=green!40!black] (0,...
Gerhard's user avatar
  • 321
0 votes
0 answers
62 views

Unknown function `corner' in for-loops

I would like to draw this graph: each side of the regular pentagon is replaced by five circular dots. \documentclass[border=1mm]{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \...
licheng's user avatar
  • 795
0 votes
1 answer
57 views

I am trying to pass a command array to the new command or a definition with a `for` loop with `includesvg`

I have learned from the following questions: "For loop" in newcommand Use pgffor to define a new command? \foreach with \newcommand how to use them together? I was trying to pass an ...
Oo'-'s user avatar
  • 269
2 votes
2 answers
362 views

How to simplify the code below by using cycles?

\documentclass{article} \newcommand[3]{\mycounter}{a=#1, b=#2, c=#3} \begin{document} \mycounter{1}{2}{3} \mycounter{4}{5}{6} Too much… and the last line is \mycounter{28}{29}{30} \end{document} I ...
Meiu's user avatar
  • 548
1 vote
1 answer
92 views

Changing order of objects in a grid

The following code draws tens frames to show adding. The input is two numbers which present in different colours. \documentclass{article} \usepackage{tikz} \newcommand{\tensframeh}[2]{\begin{...
Wendy Taylor's user avatar
4 votes
3 answers
104 views

Changing value of an array inside foreach doesn't effect the array outside of foreach

Editor: TexMaker Tex distribution: Latex I have a foreach statement, and I'm changing some of array cell's values inside of the foreach block. But it seems that the changes have not applied on the ...
z.ghane's user avatar
  • 51
1 vote
0 answers
83 views

confused with tikz looping logic

In an earlier question asked here and resolved partially, an extra cycle of execution within this function happens. As a result, there are extra labels published. Any idea what loop logic needs to be ...
jayr's user avatar
  • 229
2 votes
2 answers
92 views

Conditionals in \foreach loops

I drew a ruler using the MWE below then I realized that It draws each medium (5 mm step) vertical line over the small ones (1 mm step) and each large (numbered) vertical bar over both medium and small ...
Brasil's user avatar
  • 1,380
2 votes
0 answers
68 views

I cannot define tikz coordinate with foreach statement

I got a weird bug when I want to define and name a list of coordinates \tikz{ \foreach \name/\pos in {{a/(1,0)}, {b/(0,1)}} \coordinate (\name) at \pos ; } The error is {/usr/local/texlive/2023/...
JGressier's user avatar
0 votes
0 answers
29 views

formula in <list of values> for the command \foreach

good afternoon, My computer was on Debian 10 (buster) and I could use the following Latex code : \begin{tikzpicture}[scale=0.6] %valeurs ci-dessous à changer en fonction du repère qu'on veut \def\xmin{...
Kurt Godel's user avatar
6 votes
1 answer
126 views

Problem with foreach loop in tikzpicture - undefined control sequence

I am puzzled by something in tikzpicture. Here is the problematic code that i shrinked to its minimum: \documentclass{article} \usepackage{tikz} \usepackage{xcolor} \usepackage{pgfplotstable} \...
Etienne's user avatar
  • 115

1
2 3 4 5
18