{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

5
votes
1answer
290 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
106 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
87 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 ...
7
votes
1answer
163 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
439 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
275 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
296 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
303 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
210 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
96 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
59 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
149 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} ...
4
votes
1answer
858 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
210 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 ...
2
votes
0answers
159 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
111 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
225 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
91 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} ...
7
votes
2answers
200 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
310 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
152 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
297 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
305 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
309 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
282 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
152 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
41 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
270 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
244 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
666 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
141 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. ...
4
votes
1answer
124 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
161 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
317 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
139 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 ...
5
votes
2answers
258 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
480 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 ...
10
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
199 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
411 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
242 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
679 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
157 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
242 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
233 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
239 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
162 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
222 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
233 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
145 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 ...