{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

4
votes
1answer
66 views

How can I automate the generation of this dynamic-programming graph?

I would like to draw the following dynamical programming graph. I believe it could be sped by using the foreach syntax. The code I have started to write is \documentclass[tikz, convert = ...
5
votes
1answer
123 views

No shape is known for just created foreach nodes

This can be similarly formulated to Why are just-created TikZ shapes "unknown"?; but its slightly different. Here is the MWE: \documentclass[% 12pt, journal, onecolumn, twoside, draftcls, ...
4
votes
1answer
40 views

TikZ: issue with lines in foreach loop

\documentclass[tikz]{standalone} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \coordinate (h) at (0, 3); \coordinate (O) at (0, 0); \draw (O) -- +(-3, 0); \draw[-latex] (O) -- ...
8
votes
1answer
166 views

Increments in \foreach loop with two variables, TikZ

I'm trying to draw a stack of arrows at different angles in a \foreach loop in TikZ. I don't want to have to declare every z coordinate and angle manually so I was using the {1,2,...,10} syntax but ...
4
votes
1answer
51 views

\foreach not behaving in axis environment

Am hesitant to ask yet one more embarrassing question, but I can't seem to see the problem with the \foreach in the MWE. It should produce several horizontal lines but only produces the one with the ...
9
votes
2answers
153 views

Plotting Arrows Programmatically in Pgfplots

I'm having an issue where I would like to plot a series of evenly spaced arrows where the length is dependent on the values from a data file and I'm not particularly sure how to go about it. I would ...
3
votes
1answer
78 views

Retain coordinate value in tikz foreach loop

I would like to retain a computed coordinate value from one step of a tikz foreach loop to the next. In the code below, I would like the increment in the y-value to depend on the previous y-value, ...
5
votes
1answer
68 views

Why does this \pgfmathparse not work outside the \foreach loop?

The LaTeX code below builds in Sublime Text 2 and gives the results: 7, -3.0, 4, -9.0, 11, -9.0, 1, two, 3.0, IV, cinq, sechs, 7.0, But it gives the following errors when I remove the % ...
3
votes
2answers
53 views

Using Counters in foreach, animate

I´m trying to create an animation of rectangles approximating the area below a curve (x^2). I´ve tried to use a counter to specify the lenght of the rectangles but Latex won`t let me use \divide or ...
5
votes
1answer
84 views

Why doesn't a \foreach variable work in \draw in an \axis?

I'm finding some weird behavior with TikZ's \foreach within an \begin{axis} environment. This works: \foreach \x in {-2,-1,...,2} { \addplot[thick, domain=0.05+(\x*2-1)*pi/2:+(\x*2+1)*pi/2-0.05] ...
7
votes
2answers
133 views

An application of \foreach command in TikZ to generate labels

I would like ask you to help me solve the following application of foreach of TikZ package. By means of the following code: \documentclass{article} \usepackage{tikz} \begin{document} ...
2
votes
1answer
17 views

\the\thislevelcount is available inside a ForEachX loop, but \thislevelitem is not (the forarray package)

I'm trying to loop though a comma delimited list and print out the elements in a table. Here is the code that works half-way for doing this: \documentclass[10pt,a4paper]{article} % ...
7
votes
3answers
176 views

How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when building tables?

I am trying to build a table, and inside the tabularx environment I would like to have a loop, something like (here is a MWE): \documentclass[10pt,a4paper]{article} \usepackage{tabularx} ...
6
votes
1answer
37 views

How to add a \global before \pgfmathsetmacro?

It seems that one can't add \global before a \pgfmathsetmacro as that yields: You can't use a prefix with `\begingroup'. But that is the functionality I need here. I am trying to compute the ...
8
votes
5answers
394 views

Special case for last element with \foreach

I want to create a function that generates a list of equation references from a comma delimited input list. e.g. \erefs{eq:first, eq:second, eq:third} \erefs{eq:first} yields, the following: ...
7
votes
2answers
88 views

\foreach from 1 to 1 [duplicate]

How to make a command (without testing) that contains a foreach loop that may count from 1 to 1 if necessary ? \documentclass{minimal} \usepackage{tikz} \newcommand{\boucle}[1]{% \foreach \x in ...
6
votes
1answer
110 views

\foreach problem

I have the following problem I want to avoid a \foreach loop in a macro if not necessary, but I don't know how to do a test in a tikz picture, I undersand why \ifthenelse can not work. In my example ...
2
votes
1answer
49 views

Loop in pgfplots doesn't work

I'm trying to do a loop in pgfplots to draw a bunch of rectangles under a curve, but it doesn't work. This is my code \begin{tikzpicture}\begin{axis}[ width=160pt,compat=1.5.1,grid ...
6
votes
3answers
125 views

How can we correctly implement a list of two (calculated) variables?

I want to use foreach to loop through two variables at the same time, in Tikz. I'd like to go through the variable \y from 0 to 7. At the same time, I'd like to go through \yy from 0 to 14, by ...
6
votes
1answer
76 views

Create filled shape with \foreach

I now did it manually, but I'm interested in how I can do this with a loop: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \tikzstyle{Punkt} = [coordinate] ...
2
votes
1answer
71 views

Pointing to a node with calculated name, why do I get to the east, not to the center?

It seems like I'm doing something wrong when using foreach variables to indicate node numbers. The two foreach loops are anchoring the paths to the east of each node. Why does this happen? ...
9
votes
3answers
121 views

Why is the \endcsname not found in the following code

This is a precursor to my real question. But for whatever reason, when I tried reducing my code for something to post here, I got more errors. In particular, the following code gives me an error ...
6
votes
1answer
82 views

Cycle not working with pgfplots \foreach

I'm trying to plot some data from a text file, and I would like to be able to cycle the styles of the markers using a custom list. I was able to get the cycle list working, but when I added error ...
7
votes
4answers
331 views

How to access i'th argument of a macro?

How can I access the i'th argument of a \newcommand declaration via an iteration variable? Assume I want a command \foo like: \newcommand{\barr}[1]{argument 1 is: #1} \newcommand{\foo}[6]{ ...
1
vote
1answer
40 views

PGF’s \foreach can’t replace in [start chain=\here]?

Here in TikZ/PGF, I need two lines of dots to connect them later. – I make those dots with chains in a \foreach loop. But I can’t get the naming to work in the loop. The code below works, but ...
4
votes
1answer
80 views

Pass a list through pgfkey

I'm declaring a new shape [which looks like an Integrated Circuit]. One of the options I want to provide for this shape should be a list of positive integers with arbitrary length [which configures ...
6
votes
3answers
169 views

How can I get these two nested \foreach loops to work?

I try to use nested \foreach loops to create edges between many nodes. \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node (a) at (0, 1) {}; \node (b) at (0, ...
4
votes
2answers
128 views

How to get the number of elements in a \foreach loop?

Does the PGF command \foreach provide a simple possibility to get the number of elements iterated? It has a parameter count to hold the current element number, so a workaround is to iterate the list ...
6
votes
1answer
84 views

\alph without counters

When I iterate numbers with TikZ \foreach, they are stored in a macro. Now, when I need the letter corresponding to this macro, I can only convert it by saving it to a counter and then receiving it ...
6
votes
2answers
156 views

Creating anchors in a shape with a \foreach loop

I was playing around with this question, and in particular tried to modify and expand the linked example. It works fine, but there is an error when I try to use a \foreach loop to define the different ...
5
votes
1answer
102 views

make a table with flexible column count

I have a file which I would like to be able to generate two documents, one with narrow pages and one with wide pages. I have a figure in the document with several narrow equations, and to save space ...
5
votes
3answers
142 views

Why does cleveref's \crefname command have no effect when it appears within a \foreach?

This question follows on from this one, which I asked a few weeks ago. I have since discovered the cleveref package, and I would like to use it for ease in referring to theorem-like environments ...
4
votes
1answer
187 views

(x)ifthen in TikZ

I am searching for a way to conditionally handle some items in a TikZ \foreach specially using an \ifthenelse condition. However, the compiler responds ! Undefined control sequence. <argument> ...
3
votes
1answer
93 views

Xparse macro with optional parameter breaks value for PGF foreach

I write a document class and want to execute something a certain number of times, depending on a user-defined quantity. So I thought I'd use a foreach loop from PGF together with accessor macros: ...
2
votes
1answer
73 views

Conditional assignment in a loop

Objective: I want to compile the temporary.tex file containing PSTricks code twice. One with -jobname=Rotated and the other one with -jobname=Unrotated. The resulting Rotated.ps will be passed to ...
6
votes
1answer
128 views

using computations with \foreach in tikz

I am trying to learn \foreach in TikZ and I am confused because of all the errors I get. Here is a code sample I tried that gave me: ForeachEvaluateTest.tex:0:File ended while scanning use of ...
5
votes
3answers
289 views

Nested lists in \foreach loop in TikZ

I want to draw a bunch of nodes with different styles (a, b, ...) at different points (named 00, 01, ...). I am using the following code: \foreach \n/\lst in { a/{00, 14, 20, 34}, b/{01, 11, 23, ...
11
votes
2answers
217 views

\pgfmath and \foreach in TikZ

I am quite new to TikZ. I have the following code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{chains} \begin{document} \begin{tikzpicture}[start chain=circle placed ...
14
votes
1answer
263 views

Why does \foreach \x in {0,1,…,0}{} perform two iterations (instead of one)?

See the following MWE to understand what I mean better. \documentclass[preview,border=12pt]{standalone} \usepackage{pgffor,multido} \begin{document} \section*{foreach} \foreach \ix in {0,1,...,3}{% ...
1
vote
1answer
252 views

Drawing TikZ pictures step by step for beamer slides [duplicate]

I want to uncover/draw a picture bit by bit for beamer slides. I imagined that using \only inside a \foreach loop should work, for instance: \documentclass{beamer} \usepackage{tikz} \begin{document} ...
8
votes
4answers
199 views

Why doesn't this code combining \foreach with \newtheorem work?

Here is an example document. \documentclass[a4paper]{amsart} \usepackage{tikz} \theoremstyle{definition} \newtheorem{baseTheorem}{Base Theorem}[section] \foreach \x in ...
2
votes
2answers
88 views

Unwanted space around def-generated tabular

I'm using some code I found to generate, from simple input, a nicely formatted list of steps in solving an equation. However, my method is adding unwanted space to the left and at the bottom of the ...
0
votes
0answers
54 views

pgfplots: undefined control secquence in a foreach loop [duplicate]

I am getting an undefined control sequence when using \col in a \foreach loop. ! Undefined control sequence. \pgfkeyscurrentkey ->\col \documentclass[tikz, dvipsnames]{standalone} ...
4
votes
1answer
135 views

number format in \pgfmathsetmacro for auto-foldernaming in tikz \foreach environment

What I want to do is creating automatically the filenames of the datafiles inside a foreachloop in tikz. Maybe it's better to show a minimal example first: \documentclass{standalone} ...
3
votes
1answer
684 views

TikZ: using name intersections to define a node

Two questions: What is going wrong with these nodes that are defined from the intersections? Can this be automated with \foreach syntax to find the other vectors for the 2nd point? I couldn't ...
7
votes
1answer
171 views

double foreach for color shifting nodes

I want to draw the bottom series of circles: Here is my code: \documentclass[margin=.5cm]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[every node/.style={circle}] \foreach ...
1
vote
0answers
127 views

pgfplotsforeachungrouped in groupplot

I want to create a grid of plots with groupplots, where every plot is taken from an external file and included via pgfplots. Due to the fact, that foreach doesn't work nicely in a axis environment, ...
5
votes
1answer
102 views

change numbering when using \foreach to assign numbers for aid lines in a diagram

\documentclass[11pt]{article} \usepackage{xfrac, array, tabu, multirow, graphicx, setspace, dcolumn, tikz} \usepackage[fleqn]{mathtools} \usepackage[ngerman]{babel} \usepackage[applemac]{inputenc} ...
5
votes
1answer
214 views

Create Table for a Family of Curves

Following the issue Color Management with a Family of Curves I couldn't find a proper way of creating the associated table for a family of curves. I tried to create new columns with respect to the ...
5
votes
1answer
80 views

TikZ: Can a \foreach command run inside decoration = {markings,?

Can I use \foreach inside of decoration = {markings, ...? \documentclass[convert = false, tikz]{standalone} \usetikzlibrary{decorations.markings} \usetikzlibrary{arrows} \begin{document} ...