{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

1
vote
2answers
301 views

\pgfmathdectobase macro \pgfmathresult digit index or bitwise operators

Is there a way to access each digit of a macro returned by \pgfmathdectobase (or \pgfmathresult) which is a binary number ? This would be useful for a function which prints the power set of a given ...
3
votes
2answers
398 views

binary representation of an integer

Is there a way to get a binary string of an integer calculated by e.g., \pgfmathparse{pow(2,3)} \pgfmathresult such that later on I can use the string digits in a foreach loop like .. if it is '1' do ...
10
votes
3answers
530 views

Macro to access a specific member of a list

I want to be able to have a macro access a specific element of a list. The following code works, however requires me to have two separate macros: one that accepts a list, and the other that accepts ...
11
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 ...
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 ...
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
408 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} ...
7
votes
1answer
881 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 ...
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
344 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
503 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, ...