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
1 answer
40 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
  • 731
1 vote
1 answer
53 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
  • 731
0 votes
1 answer
68 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
103 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
35 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
62 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
194 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
53 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.3k
0 votes
1 answer
39 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
3 votes
3 answers
128 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
188 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
90 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
41 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
73 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
239 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
72 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
77 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
58 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
  • 773
0 votes
1 answer
51 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
353 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 ...
Axia's user avatar
  • 173
1 vote
1 answer
86 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
82 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
74 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
84 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,286
2 votes
0 answers
63 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
26 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
107 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
4 votes
4 answers
600 views

scanf functionality in TeX?

Is there a function akin to scanf of C that can simultaneously parse stdin or txt and assign them to variables? For example, I am trying to typeset a pdf from a text file. The first line contains the ...
qem69331's user avatar
3 votes
2 answers
280 views

tikz foreach floor function

It seems that in a tikz-foreach-loop mathematical expressions are not evaluated correctly: \documentclass{minimal} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \c [count=\i] in {0,...
Brauer Suzuki's user avatar
0 votes
1 answer
145 views

How to perform arithmetic operations

I'm trying to draw polygons and label nodes at their corners in clockwise order. \begin{tikzpicture}[node distance=3cm, thick, main node/.style={circle, draw, font = \sffamily\Large\bfseries}] \...
Vincent Phillips's user avatar
0 votes
0 answers
37 views

Using a `foreach` command to repeat a row of three congruent sectors in a `TikZ` diagram

I would like to use a foreach command to make nine more rows below the row drawn with the following command. \documentclass{amsart} \usepackage[dvipsnames]{xcolor} \usepackage{tikz} \usetikzlibrary{...
user143462's user avatar
  • 1,039
2 votes
1 answer
112 views

TikZ / foreach: read out sequence of Unicode symbols

How can I read out \char"1F0A1,...,\char"1F0DF that means \char127137, ..., \char127199 with a foreach-loop? I got Dimensions too large if I use the second version; and TikZ does not like ...
cis's user avatar
  • 7,879
2 votes
2 answers
183 views

How to use loop for creating defined number of newcommands counting authors

For my template I want to create possibility to define a number of authors and automatically create a respective number of variables/commands which save the name of any author and make it able to ...
lukeflo's user avatar
  • 1,545
2 votes
2 answers
90 views

Pgf foreach ungrouped displays list twice

While trying to give a foreach loop a macro to loop into, I found on Macro not working in foreach loop that I can use \pgfplotsforeachungrouped and it was indeed able to loop through my macro. However,...
Balansoire's user avatar
3 votes
2 answers
111 views

TikZ / foreach: Create a list of randomly arranged numbers without repititions

I need a list in which the numbers 1, 2, ..., 52 are randomly arranged - but without repetitions! Is there a simple implementation for this? How can I do that? In the following MWE I will use the ...
cis's user avatar
  • 7,879
2 votes
2 answers
70 views

TikZ / pgfmath: How to get several numbered variables?

Is there a way to create several numbered variables (like \x1, \x2,..) in a loop? BTW: I do not need to use \usetikzlibrary{math} if there is solution without the math-library. \documentclass[a4paper]{...
cis's user avatar
  • 7,879
2 votes
1 answer
76 views

TikZ: repeat a certain step between all other foreach-steps

I have a (long) list, say \def\List{0, 4, 7, 11, 2, 3}. I draw an animation with a foreach-loopfor that (this is a very small part of a very large tikzpicture): But I would like to repeat the ...
cis's user avatar
  • 7,879
0 votes
1 answer
58 views

I do not understand the error. Is there a limit to the number variables in \foreach?

It always issues an error if I use \markthree in the last row, see below. The error is ! Missing number, treated as zero. { l.60 } A number should have been here; I inserted 0'. (If you can't ...
Jun's user avatar
  • 39
2 votes
2 answers
61 views

Illegal unit, and missing number when trying to define variables

When trying to make a sequence of graphs of step functions, I wrote the following code snippet: \begin{tikzpicture} \pgfmathsetmacro{\n}{2^3}; \pgfmathsetmacro{\step}{1/\n}; \foreach \i in {0,\step,......
Addem's user avatar
  • 867
0 votes
1 answer
94 views

My wheel chart displays fine but I have an error in the logs

I am trying to create a wheel chart and it displays almost fine but i still have an error: Package tikz Error: Cannot parse this coordinate. ‪main.tex, 32‬ See the tikz package documentation for ...
Balansoire's user avatar
1 vote
2 answers
104 views

How to draw a graph with a row of incomplete semi-circles with a few extra edges in TikZ

I want to draw something like the hand-drawn picture I have attached (the second picture). This is actually a portion of the line digraph of Figure 2 (with a specified orientation), which I have also ...
Emily's user avatar
  • 125
0 votes
0 answers
44 views

How to perform a foreach loop over a \def variable [duplicate]

I want to perform in LaTeX a foreach-loop over a def variable: \def\material{Computer,Internet,Home-Folder} \begin{itemize} \foreach \x in {\material} { \item \x } \end{itemize} I want to get ...
jochen's user avatar
  • 11
1 vote
1 answer
80 views

Declaring variables in Tikz

I have a Tikz graph of a step function which I'm trying to draw, and I think most of it is boiler-plate, but the part that I wrote which isn't working as I'd hoped is: \foreach \i in {0,1,...,5} \...
Addem's user avatar
  • 867
2 votes
2 answers
221 views

Defining coordinates in `foreach`

I want to define in a \foreach loop a bunch of coordinates in terms of previously defined coordinates: \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \coordinate (A0)...
Osmin's user avatar
  • 35
0 votes
1 answer
71 views

How to create a matrix with a loop performing pycode

Okay, so there are a bunch of questions that are SO close to what I am trying to sort out, but I can't find a combination of approaches to make this work (I am so sorry if this has been answered ...
jesse's user avatar
  • 215
5 votes
2 answers
223 views

It is possible to make point as one variable?

I trying to run this code: \begin{tikzpicture} \foreach \n/\p in {b/(1,1),c/(2,1)} \node[draw,circle] (\n) at (\p) {}; \end{tikzpicture} % This is *not* working And I got error. I'm ...
heblyx's user avatar
  • 2,571
2 votes
1 answer
194 views

Automating a scalable sine wave code

From the answer to this post, inspired by the code of Qrrbrbirlbel`s comment, I came up with this solution; which I posted in this answer. Now how can I use \foreach loops to automate this solution? \...
Hany's user avatar
  • 4,679
0 votes
1 answer
28 views

Can you define a varaible that you then use as the list of elements to \foreach loop over? [duplicate]

I have a piece of code where I'm iterating over a list of items, but I do this in several places and would like to avoid having to redefine that list every time. This is what I have working: \foreach \...
anf3's user avatar
  • 1
0 votes
1 answer
66 views

Problem using \foreach loop

I'm still new to LaTeX and I can't wrap my head around the foreach loop. I want to draw a grid and some semi-circles on some chosen points. Here's my minimal Non working example : \documentclass[10pt, ...
Kawahiem's user avatar
3 votes
2 answers
145 views

Multiple plots from a file by changing the value of a meta parameter

I want to plot a bunch of curves on the same axis. They are all functions of two variables, let us call them x and p. I want to make plots y=f(x,p) with x as the x-axis variable for a fixed value of p ...
Níckolas Alves's user avatar

1
2 3 4 5
17