{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

7
votes
1answer
98 views

Tikz binomial distribution

I'm trying to plot the pmf of the binomial distribution for particular values of N and p. For example, when N=10 and p=0.5: \documentclass{article} \usepackage{amsmath} \usepackage{pgfplots} ...
3
votes
1answer
76 views

two variables foreach loop problem

I want to draw a pulse train on which I write some information like the corresponding angle, etc... But I think I've got a problem with the two variables foreach loop because I can't even compile ...
2
votes
0answers
39 views

Variable in \foreach,

I would like to show you my problem. Here you have the script to generate a picture.Now I need to generate a second picture in which the arrows are not equally spaced any more. ...
8
votes
1answer
76 views

drawing path in foreach loop with pgfsetmacro

I have N points on a circle, I want to draw the intersection of the convex hulls of all sets of N-k consecutive points. The points are not evenly spaced. The values of N and k (and the actual angles ...
5
votes
2answers
88 views

How to use \x from \foreach loop in the parameters of \draw in tikz

In order to make it simple, I want to draw concentric circles fading out with something like \foreach \x in {1,1.5,...,4} \draw[color=black!{100-10*\x}!white] (0,0) circle (\x); The problem is I ...
2
votes
1answer
71 views

Calculate label angle from a value list

As a beginner of tex and tikz i stuck on array handling together with foreach. I would like to draw two circle with text along its circumference. \documentclass[tikz]{standalone} ...
4
votes
2answers
79 views

Using pgffor's \foreach to place graphics into a tabular

I want to arrange EPS graphics (included via \includegraphics) in a tabular using \foreach. Currently this is done without any loops like this: ...
9
votes
3answers
267 views

How to tell TikZ to first compute and then display a variable?

I want TikZ to first compute and then display the value of a variable. The question is, for sake of simplicity, based on this concrete example from TeXample.net: \documentclass{article} ...
6
votes
0answers
59 views

tikz foreach loops: is there an equivalent of metapost's step?

I apologise if I'm using and searching with incorrect terminology. This seems an obvious question (to me) so I'm surprised I've not found anything (and so assume I'm missing something). In metapost, ...
2
votes
1answer
38 views

Illegal unit of measure (pt inserted) error when using \foreach with node[pos]

I am trying to draw a path and position nodes on it and fill them using this code and it works \documentclass[varwidth=20cm]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw ...
8
votes
2answers
227 views

Dynamic upper bound for foreach loop

I want to read the upper bound for my foreach loop from a file. I've tried the following, but it gives all manner of errors. \documentclass{article} \usepackage{tikz} \begin{filecontents*}{foo} 42 ...
1
vote
1answer
58 views

\pgfdeclareshape: how to define anchors in a loop?

I think my question is quite similar to this and this, however I didn't manage to modify the provided solutions to fit my problem. In the following MWE I am trying to define 8 pin anchors in a ...
0
votes
1answer
54 views

How can I connect centers of nodes defined using let in a foreach loop?

I want to create a star polygon using a \foreach loop to make nodes for the vertices and another \foreach loop connecting, say, every 4th node. \documentclass[12pt]{amsart} \usepackage{tikz} ...
3
votes
2answers
67 views

Using \foreach to generate functions

I wish to plot a function based on collection of simple functions. For instance, the maximum of some functions: \begin{tikzpicture}[] \begin{axis} \addplot[smooth, color=black] { max( 2*x, ...
2
votes
0answers
64 views

Passing an array type argument for new command

I've looked around and can't seem to find anywhere, but I was wondering if there is somewhere you can do something like the following: \newcommand{\loopy}[1]{ \begin{tikzpicture} \foreach ...
3
votes
1answer
46 views

Using \pgfplotsinvokeforeach in foreach loop

I am trying to run a \pgfplotsinvokeforeach loop in a \foreach loop to plot the variables var1_roll1 - var1_roll10 in one plot and var2_roll1 - var2_roll10 in another. Both loops work fine ...
0
votes
0answers
16 views

How to debug the “Argument of \XC@definec@lor has an extra }” error in Foreach statement? [duplicate]

First, I draw three nodes each of which has three parts. Everything is OK. The code and the image are as follows. \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[]{tikz} ...
0
votes
1answer
80 views

Generate table using the foreach command from pgffor [duplicate]

I want to generate a table from a list. However for some reason it fails to work. I searched: PGFplots foreach equivalent to TikZ's with multiple variables separated by a slash Copy table row n ...
3
votes
3answers
191 views

Summation of a list of numbers

The next code gives : 1 1.2 3 But 1 2.2 5.2 is expected. What is wrong ? \documentclass[tikz]{standalone} \begin{document} \xdef\Sum{0} \foreach \i in {1,1.2,3} { \pgfmathsetmacro\Sum{\Sum+\i} ...
4
votes
1answer
112 views

Using knitr, beamer, and /foreach to produce unique section titles in pdf from R string variable

Using R, knitr, and beamer, I have created a pdf that contains a graph for each school in our district. I read in each graph using the \includegraphics command within a /foreach loop. I want to ...
3
votes
1answer
76 views

Build tabular content via \foreach

I am trying to build up tabular data using the solution at How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when building tables?, but not having any ...
5
votes
1answer
48 views

csuse with foreach

Am having difficulty determining the correct syntax for using \csuse from the etoolbox package with a \foreach. I have a list, and for each element in this list I need to create a new list. To ...
7
votes
2answers
177 views

How can I draw an arrowhead only at the end of a path drawn with \foreach?

I want to define a command for drawing some special polygonal lines with pgf/tikz. In these polygonal lines, the line styles are of alternating change. The following is my latex code: ...
6
votes
3answers
186 views

Long List of Files Names with Paths

I need to keep a list of files (max of around 500) along with the path. Based on the fact that each file name and path could be up to 100 characters, should I just save it in a comma separated list ...
4
votes
1answer
75 views

Extract from a token containing a list with math content

I have a token which contains a list consisting of: a date in YYYY-MM-DD format, followed by a colon, and some text which may contain math. The text will consist of a sentence or two (i.e., no ...
4
votes
2answers
136 views

Piecewise linear plot with custom grid

I try to plot a piecewise linear interpolation of a function w on a grid \xn={x1,x2,...,xN} using tikz. I tried using a foreach loop and store the grid as a vector to do that, but it doesn't seem to ...
4
votes
1answer
45 views

Why does it matter where I'm trying to call my \foreach loop from? [duplicate]

I was trying to post a solution to How can I draw 25 horizontal lines instead of these 25 marked samples?, but I got stuck with a \foreach loop which wasn't behaving as I expected it to. Here's my ...
3
votes
1answer
131 views

My personal TikZ template to be easily changed

Every time I need to plot a simple function (eg. a parabola), I use a self-made TikZ template that is: \documentclass{minimal} \usepackage{pgfplots} \pgfplotsset{/pgf/number format/use ...
5
votes
1answer
123 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
173 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
63 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
511 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 ...
5
votes
1answer
79 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
224 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
114 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
135 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
87 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 ...
6
votes
1answer
118 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] ...
8
votes
2answers
206 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
24 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} % ...
11
votes
3answers
292 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} ...
7
votes
1answer
71 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
415 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
112 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
171 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
74 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
140 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
99 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
80 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
141 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 ...