{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
2answers
182 views

TikZ: naming paths in a \foreach and accessing them later

\documentclass[convert = false, tikz]{standalone} \usetikzlibrary{calc} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \coordinate (P1) at (60:4cm); \coordinate (P2) at ...
2
votes
2answers
292 views

TikZ: drawing an evolution of an ellipse to a hyperbola with the same focus

Is there a high speed way to draw the evolution of an ellipse, to a parabola, and then into a few hyperbolas with the same focus? From the picture, we see that we start out with three elliptical ...
5
votes
2answers
144 views

Color Management with a Family of Curves

I am struggling with following fairly simple looking problem of plotting a family of curves. \documentclass[border=1mm]{standalone} \usepackage{pgfplotstable} \pgfplotsset{compat=1.8} ...
8
votes
1answer
292 views

TikZ: Automating a process with a for loop instead of coding in each piece

I am positive I could create the incoming hyperbolas and then the deflections by the planet by hand for each one, but how the image is set up conjures up the felling this could be done through ...
8
votes
2answers
254 views

StrSubstitute for multiple replacements in a loop?

I am trying to replace multiple keywords using \StrSubstitute inside a loop using foreach - but unable to accumulate all the results. The result of each \StrSubstitute call is getting lost inside the ...
5
votes
2answers
277 views

TikZ: Combining multiple paths in and outside foreach

I am trying to generate a path from a list of directions (as seen on the numpad). The coordinates are generated correctly, but because I use multiple call to \path the arrowheads are drawn on each ...
7
votes
2answers
251 views

TikZ: \foreach in macro with argument as list

The code below generates: What I expect is: Why does the \foreach seem to treat the entire list as one value? How do I fix it? \documentclass{article} \usepackage{xparse} \usepackage{xstring} ...
2
votes
1answer
134 views

Error compilation tikz, intersection & foreach

I want to compile this code (using PDFLaTeX) \documentclass[12pt]{article} \usepackage[ansinew]{inputenc} \usepackage[T1]{fontenc} \usepackage{tikz} \usepackage{color} ...
1
vote
0answers
39 views

Iterate over certain matrix cells [duplicate]

I have a matrix and want to reference several nodes of this matrix. How do I add a line for some of the cells? I came up with this: \documentclass[12pt]{scrbook} \usepackage{tikz} ...
4
votes
1answer
184 views

Trouble using pgfmathsetmacro in foreach loop more than once

I'm trying to draw a series of lines where the x-coordinate is given by a geometric sequence, as in the following example: \begin{tikzpicture} \foreach \i in {0,...,3} ...
5
votes
1answer
228 views

Complex Count in \foreach for number line

I am looking to create simple number lines. I have asked a similar question: Resetting numerical labels in \foreach commands on a numberline. But now I am in a different situation. I know how to ...
28
votes
3answers
619 views

Why doesn't TikZ's \foreach iterate over the last element of the list?

This code \documentclass{report} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[dashed] (1,-1) -- (1,2) node[above] {$1$}; \draw[dashed] (2,-1) -- (2,2) node[above] {$2$}; \foreach ...
4
votes
1answer
126 views

Errors in passing a previously concatenated string to foreach

Motivation While attempting to answer Pie chart with values as angles not percent, I stucked on passing a string to a foreach. The context To makes things clear, I briefly introduce the context. ...
3
votes
1answer
111 views

PGF's \foreach when list requires completion

Please is there anything I am doing wrong that PGF's \foreach is failing here? \def\alist{} \foreach\x in {% 2pt_A,4pt_A,...pt_A,10pt_A }{% \xdef\alist{\alist\ifx\alist\@empty\else,\fi\x}% } ...
4
votes
1answer
144 views

A list of pairs in pgfkeys

Having learnt a lot about the pgfkeys package as a result of my last question, I'm now trying to do some more adventurous things. Let's say I have a command called \blob, whose value is the ...
7
votes
2answers
273 views

Resetting numerical labels in \foreach commands on a numberline

I am looking to create quick number lines. What I have so far is this: \documentclass[letterpaper,12pt]{book} \usepackage{tikz} \usetikzlibrary{shapes,snakes,backgrounds,arrows} \begin{document} ...
1
vote
2answers
126 views

looping using both arabic numerals and actual numbers

Is there an easy way to loop this script in .tex: \immediate\openout\mytest1=test1.tex \immediate\openout\mytest2=test2.tex \immediate\openout\mytest3=test3.tex \immediate\openout\mytest4=test4.tex ...
4
votes
2answers
219 views

How to use declared TikZ functions in \foreach condition?

How is it possible to use a declare function in the condition of \foreach? Here's my MWE: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[declare function={a = 0; b = ...
7
votes
1answer
412 views

Tikz: \foreach and axis environment incompatibility

I'm trying to plot a figure with TikZ. I have a few .txt files with the coordinates of the curves that I want to plot, in a list such as file2.txt, file4.txt, ... file30.txt and I want to add ...
9
votes
1answer
2k views

TikZ \foreach loop evaluate variable using pgfmath function

I have problem with defining a new variable within the \foreach loop using the evaluate option using a pgfmath function: \documentclass{article} \usepackage{tikz} \begin{document} ...
6
votes
1answer
185 views

Determining tikz drawing style, depending on the values of two nested loop iterators

So the question is a tikz one! Assume that you are drawing things inside two nested foreach loops in tikz, and the iterator variables are \x and \y. What I'd like to obtain is to be able to specify a ...
5
votes
1answer
382 views

Syntax for smoothing a coordinate plot with the foreach command

Currently implementing the solution of Curve synthesis - Adding two curves to get another one. I would like to smooth out the resulting curve. The present code: % red line \path[red,name path=one] ...
7
votes
2answers
225 views

Using foreach loop in TikZ to plot at non-uniform locations

As a Teaching Assistant for a class, I am trying to draw a seating chart for the professor. The seating chart will have a photo of each student, the student's name, and where the student is sitting in ...
6
votes
1answer
587 views

tikz label coordinates using mathematical expression from foreach variables

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \x [count=\xi from 1] in {-3.0,-2.8,...,1.8} \draw[thin] (0,0) ++(\x,2) rectangle ++(0.2, 0.2) ...
2
votes
2answers
143 views

What is the correct way to generate notation for a finite set using for loop in Latex?

I am trying to create a command that will take an index n as a parameter, and generate the the expanded form of this {a_1, a_2, a_3,...,a_n}. For my first attempt, I tried to use the syntax suggested ...
4
votes
2answers
216 views

Tikz: Using relative positioning and foreach variables

I want to generate a picture that replicates itself and slowy fades out. For that i plan to use a foreach statement and redraw the picture to its rigth. How can i use the foreach variable to position ...
4
votes
0answers
232 views

Drawing a gear with Tikz [duplicate]

I need some help to modify the \gear macro of this answer in order to be able to fill the drawn gear with a solid color. I've tried to move the \draw command outside the loop, but it does not work as ...
6
votes
2answers
214 views

tikz/foreach: Protect space after “iteration variable”

I try to draw some nodes in tikz, and as they are very simple I wanted to "shorten" this using a \foreach command: \foreach \xnum in {1,2,3,4,5} { \node at (X\xnum center) {$x_\xnum$}; } You ...
3
votes
1answer
149 views

Using foreach to generate computed indices in a plot

I have a table with 8 columns, and I want to generate 4 plots (1 vs 0, 3 vs 2, 5 vs 4, and 7 vs 6). I was going to use foreach to generate the plots using \begin{tikzpicture} \begin{axis} \foreach \x ...
1
vote
0answers
205 views

tikz foreach used for number in filename for addplot [closed]

I have quite a few tables generated which I want to plot in the same TikZ figure (using pgfplots). I am currently trying to use a foreach loop to plot them all, but it is only plotting the last ...
3
votes
1answer
220 views

How to make hyperlinked tabs with specific colors?

I modified this project How to print section titles like tab-list? in the following way: usletter, 8 tabs on the edge of paper, odd pages only, text within the tab is set by the user (\TabText), ...
6
votes
3answers
138 views

Expansion issue when adding to CSV list from within a \foreach

Another expansion issue that I am unable to guess at the correct combination of \edef/\expandafters to get to work. Background: Below I have defined \AddToCommaSeparateList which uses \g@addto@macro ...
5
votes
1answer
222 views

tikz gives null character in \document

Please why does \begin{document} \begin{tikzpicture} \foreach \x [remember=\x as \lastx (initially A)] in {B,...,H}{% $\overrightarrow{\lastx\x}$, } \end{tikzpicture} \end{document} give Missing ...
10
votes
1answer
236 views

\foreach has a problem with ‘initially’ argument in remember part

Is there an error in my code or did I find a bug? It seems like the \foreach statement doesn’t increase \lastn if there is an initally (value) but it works with a manually given initially value ...
6
votes
2answers
296 views

How to make global a color list definition with \@namedef done inside a foreach loop

Motivation As stated in the title, I'm trying to define a command able, from a list of colors as input, to create a list in which colors are numbered. This, manually, has been done in Arrows ...
7
votes
3answers
154 views

Defining commands using two loops

I would like to define a series of command using two loops. For instance I want to create a series of variables that can have YY or NN as subscripts. I would like to define commands \yy and \nn that ...
11
votes
3answers
364 views

Using \foreach loop in Cubic B-spline curve refinement

This question is only about TikZ (/PGF) implementation. This is a MWE of what I want to ask for: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \begin{document} ...
7
votes
3answers
337 views

How to invert list used for a tikz foreach loop

Given \def\stuff{a,b,c} I would like to be able to do \foreach \x in {c,b,a} {...} without inverting the list \stuff manually. For example is there some sort of \invert macro that would allow me ...
5
votes
2answers
173 views

Have \foreach restart or loop

I understand that trying to have a "loop function" like \foreach loop sounds like a paradox but I'll try to explain what I mean. Recently, I've asked a question about automatising the creation of ...
9
votes
3answers
609 views

Draw a path between many nodes using foreach

I'm running into a weird problem here... I have very many nodes defined, and I would like to draw a path from the first to the last using foreach. But, when I try, it just draws edges between p1 and ...
6
votes
2answers
178 views

Using etoolbox macros in tikz foreach loops

I am trying to wrap my head around etoolbox for use with TikZ. In this example (I know there are probably simpler ways to do this), I would like to draw a series of rectangles that are next to each ...
4
votes
1answer
615 views

How to loop through a list of tikzpicture within animateinline?

I have the following code which uses animateinline and several tikzpicture for it's animation effects: \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage{tikz} \usepackage{ifthen} ...
4
votes
2answers
707 views

TikZ: Drawing the same data with scatter plots and parallel coordinates

I am new to TikZ and trying to recreate the following image (which was created in R): (Translation: correlation = +1, correlation = -1, two clusters, circle, normal distribution) Each "column" ...
10
votes
4answers
325 views

How to change the item separator in TikZ foreach command

I want to cycle over several sentences using a foreach loop. Now sentences will prpbably contain commas, which are used by foreach as item separators. So I would like to change the item separator to ...
5
votes
2answers
460 views

tikz \foreach dynamic list with environment arguments

I'm making an axis environment that recieves 5 arguments (the first is optional and it's 1 by default). To make the x marks on the x axis I use \foreach \x in {#2,...,#4} {\ifthenelse{\x = 0}{}{\draw ...
10
votes
1answer
353 views

Why do paramaters of \renewcommand need to double up the # within a \foreach

Introduction: When you use \renewcommand within another macro or environment, one needs to double up the ## to access the parameters of the inner macro. This serves as a way to distinguish the inner ...
2
votes
3answers
191 views

Macro to check if an element is a member of a list, and access associative lists

Inspired from Macro to access a specific member of a list. I want to have a macro implementing the lisp functions (member item list) and (assoc id alist). The first checks if an item is contained in ...
6
votes
1answer
269 views

How to define macros in a foreach loop with effects between iterations and after the loop without using global?

Without using \global, the following code: \documentclass{minimal} \usepackage[T1]{fontenc} \usepackage{tikz} \usepackage{etextools} \newcommand\appendbyforeach[2]{% ...
6
votes
1answer
323 views

How to assign values with foreach?

I have trouble to assign values with \foreach. Can somebody help me? The following code is wrong. The purpose is to asing the values: \lx1=1, \ly1=2, \lz1=3, for example. \foreach \x/\y in ...
12
votes
1answer
310 views

How to expand a macro used in the range of a foreach loop?

Motivating Example: Suppose that I want to draw the following tree: root / \ / \ / \ A B C D This is easy enough to do by explicitly drawing the two subtrees as children of ...