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

learn more… | top users | synonyms

12
votes
3answers
3k views

TikZ Drawing a changing vector field in a grid

So far I succeeded in drawing a simple grid along with it's centres using grid and nodes. \draw[step=1] (0, 0) grid (4, 3); \coordinate (a) at (0.4, 0.3); \coordinate (b) at (3.8, 0.8); ...
12
votes
1answer
3k views

Increment loop variable in inner foreach loop

I need the following pairs of numbers: 12 13 14 23 24 34 My first attempt was to use two nested foreach loops: \foreach \x in {1,...,4} { \foreach \y in {\x+1,...,4} { % This would be very easy in ...
5
votes
3answers
363 views

Is there a \foreach function that works in the preamble?

Tikz/PGF has an extremely useful implementation of \foreach, which allows for instance the construction \foreach \x / \y in {1/a,2/b,3/c,4/d} {\x is a lot like \y} in which you can iterate over a ...
9
votes
1answer
5k views

simple arithmetic on index of foreach statement in tikz

Is foreach really a tikz statement or is derived from some other package? I would like to draw a horizontal axis with 7 ticks spaced 1 cm apart. I'd like to place a label under each tick that is the ...
21
votes
2answers
3k views

PGFplots foreach equivalent to TikZ's with multiple variables separated by a slash

I like TikZ's capability to traverse multiple variables separated by a slash in the foreach (as in the example below). I am looking for something equivalent in PGFplots? I saw in the documentation ...
8
votes
2answers
2k views

Nested foreach loop in TikZ

I would like to draw some vector fields on a triangle, and I am using nested \foreach loop to do that, however in the inner loop, you can't use the outer loop variable as the numeric range. For e.g. ...
3
votes
1answer
409 views

Use of \foreach and \csname<macro name>\endcsname together

When I compile this minimum LaTeX file: \documentclass{report} \def\defMacro#1#2{\expandafter\def\csname#1\endcsname{#2}} \def\useMacro#1{\csname#1\endcsname} \usepackage{pgffor} \begin{document} ...
14
votes
4answers
2k views

pgffor: Special treatment for last item in \foreach-list

Is there a way for handling the last item in a \foreach-list in a special way. An example might illustrate an application for that: \documentclass{minimal} \usepackage{pgffor} \begin{document} ...
7
votes
1answer
886 views

Generating tables with \@for command

I'm making a report template that requires the list of authors to be presented in several different ways, one of which is a table that lists each author and provides a space for them to sign the ...
15
votes
3answers
380 views

How keep a running list of strings and then process them one at a time

I would like to keep track of all the \AddRef commands in a document and then process them one at a time, for instance print them in the document on one line per value. It seems that this should be ...
19
votes
1answer
3k views

TikZ \foreach loop with macro-defined list

I have a small problem with the TikZ \foreach loop whenever the list, over which we loop, is defined my a macro. The following code example will show my problem: \documentclass{scrartcl} ...
7
votes
2answers
1k views

Iterate over space-separated list

I’ll briefly explain the background in case this can be solved simpler but I’d still be interested in an answer to the actual question, too. My chapter titles are very narrow and use a large font so ...
6
votes
2answers
4k views

How to use parameter numbers and \foreach

Is there a way to use the TikZ \foreach command to do operations with parameters? E.g. I would like to be able to write (just a silly example): \newcommand{\foo}[9]{ \foreach \x in{1,2,...,9}{ ...
3
votes
1answer
1k views

Drawing a Markov chain - How do I update the value of a variable in TikZ?

I would like to plot a simulation of a Markov process in R^2. Basically, I want to draw a line that starts at (x_0,y_0)=(0,2) and then follow this rule: For each i=1,...,10, the line will go through ...
4
votes
1answer
346 views

Are there list building macros in PGF/Tikz?

In Mathematica, C# linq, or other languages, we can use auxiliary functions to produce list of certain pattern. For example: In Mathematica, we can use Table[] or Range[] to produce a list of ...
3
votes
2answers
507 views

Unexpected tikz/counter behaviour

What I've been trying to do, futilely, is to use the foreach[counter=\xi] x in {1,2,3} statement in tikz/pgf with LaTeX. This fails, every time. Whatever. So I moved on to trying to use a counter, ...