{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
38 views

How can I determine the size of an array containing macros with optional parameters?

I am using my solution from How can I determine the size of an array? to count the number of entries. However, the \foreach/\IfStrEq in \SetArrayLength seems to have a problem when an entry is macro ...
2
votes
1answer
28 views

Change color in addplot in for loop of pgfplots

I am looping over several files and plotting the content on an axis in pgfplots. I would like to plot each entry as a different color (a shade of blue, for example). While the plotting works fine, I'm ...
2
votes
2answers
62 views

Call command based on comma-separated list

I have several commands, called \cata to \catd. Now I need a command which loops over a given, comma-separated list, and calls the respective command. My current approach is: ...
2
votes
2answers
34 views

\foreach and \StrLen

I don´t know how to make a foreach with a StrLen inside it, is it possible? \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} \usepackage[brazil]{babel} ...
0
votes
1answer
41 views

Rounding calculated values of parameters in TikZ when an integer is required

I can't get the full labeling of the x axis in the following graph (intended to serve as a template for different values of the parameters). \documentclass[tikz,margin=.5cm]{standalone} ...
4
votes
2answers
46 views

Tikz: order of execution of child options when foreach operation is present

I'm trying to write a code that will draw a tree consisting of 2 children for each node up to a specified depth. The drawing of the tree itself works but applying the styles (which are numbered ...
3
votes
1answer
19 views

Foreach - evaluate - modulo problem

In this MWE, the mod function doesn't work. \documentclass[margin=5pt,tikz]{standalone} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \foreach \i [evaluate=\i as \x using ...
2
votes
0answers
48 views

how to use a \global \foreach? [closed]

Is it possible to make a global foreach? How is the correct way to define arguments inside a \csdef command? \documentclass[a4paper,12pt,hidelinks]{article} \usepackage[utf8]{inputenc} ...
2
votes
1answer
29 views

pgfplots: calculating intersections and drawing arrows to the axis with foreach

I am trying to find the intersection points between two curves and draw arrows from each of them to the x-axis. I tried the following code: \documentclass{article} \usepackage{pgfplots} ...
11
votes
1answer
230 views

foreach with colors leads to “undefined control sequence”

The following MWE works nicely when I remove the optional argument [\forcol] from the \addplotcommand or when I change it to red, for example. Though I would like the curves to have different colors ...
2
votes
0answers
62 views

Using For loop in latex to input multiple files in different directories

\documentclass{minimal} \usepackage{chngcntr} \usepackage{pgffor} \newcounter{question} \newcounter{answer} \setcounter{question}{0} \setcounter{answer}{0} \newcommand\Que[1]{ ...
5
votes
2answers
56 views

Change Tikz style dependent on foreach counter value

I have a recursive macro that relies on a counter within a tikz \foreach loop. What I have not achieved is how to get a tikz style (what I've called fillMod) to be dependent on the counter value (i.e. ...
0
votes
1answer
14 views

Matrix node inside foreach loop give error when multiple columns

This question is different from \foreach inside \matrix questions 1 and 2. I was trying to do this question 3dmatrix. The \matrix command, when put inside \foreach gives the following error when ...
2
votes
1answer
48 views

Error using array and node in TikZ

I am new in TikZ and I am trying to make a graph with 12 nodes in a ring shape. My code below is not working: \begin{tikzpicture} \def \n {12} \def \radius {3cm} \def \margin {8} % margin in ...
2
votes
0answers
15 views

expand keymacro in foreach loop

Sorry, this must be a very beginner's thing, but I cannot figure out how to get the macro expanded in the loop. I tried expandafter, csname, but don't get it working. \documentclass[]{minimal} ...
4
votes
2answers
51 views

Newcommand inside foreach: multiple arguments and minipage environment

I am trying to define multiple, sophisticated newcommands within a foreach loop. This sounds so simple, but why is it so hard ? Naive attempt: \documentclass{report} \usepackage{tikz} \foreach \i ...
2
votes
2answers
41 views

Execute a macro based on number of columns in tabular environment

I want to define a special case of the tabular environment where each column heading is underlined, but there is a gap between each underline, like this: \begin{tabular}{c c c c c} Col1 & Col2 ...
4
votes
0answers
55 views

String concatenation in Tikz

How can I replace the sequence (in a pgfplots, Tikz environment) \addplot[black] table {plot3/fnxspy1.txt}; \addplot[black] table {plot3/fnxspy2.txt}; \addplot[black] table {plot3/fnxspy3.txt}; ...
0
votes
1answer
173 views

How to color multiple plots in rainbow colors?

I´m trying to color multiple curves of a line in rainbow colors wiht tikz. I´ve found the [wave] option for color from the xcolor pagacke, but I can't get it to work inside tikz's draw command. ...
8
votes
3answers
312 views

Draw all existing intersections

I have a set of arrows that intersect a circle and I want to highlight all intersections dynamically. I know that I can find those intersections via tikz' name intersections but I can't get it to ...
4
votes
3answers
174 views

Tikz: cycling through a foreach function

I would like to cycle through the terms in a \foreach function. Here's my code: \foreach \n in {cdof,cc,cdus,ads,aiw} \draw [->] (\n) |- ($(\n)+1$); However, as expected, this breaks down as ...
9
votes
1answer
91 views

Using \foreach in tikz

I'm new to tikz and I'm trying to get my head around the \foreach function. Here's my code: \documentclass[border=10pt]{standalone} ...
9
votes
3answers
227 views

Using \foreach inside a draw command using TIKZ

I'm brand new to using \foreach but not coding in general. Following the code in answer number 40 of this example: How to draw tangent line of an arbitrary point on a path in TikZ How can I properly ...
5
votes
3answers
169 views

ifthenelse inside TikZ: not working

I would like to to get this: I tried using ifthenelse inside foreach but I get an error: Missing number, treated as zero. <to be read again> = l.9 }. Here esdd says ...
3
votes
1answer
102 views

define different positions in foreach

in the following code \begin{tikzpicture} \foreach \pos in {0,...,5} { \pic at (1.85*\pos,0) {cross}; \node[formula] at ($(1.85*\pos,0)+(0.4,0.4)$) {Na}; } \end{tikzpicture} can ...
4
votes
2answers
154 views

How to access the arithmetic value of count in \foreach, and use them in rotate box{}?

I have a question about access the mathematical value of count in \foreach, I will used that value to do some calculation in the following code. But it didn't work. ...
2
votes
1answer
115 views

Custom PSTricks directory tree to TikZ

I have a PSTricks implementation of a custom directory tree which I find quite appealing. I basically want to convert the whole thing to TikZ. I managed to get the very basic idea running in TikZ: I ...
3
votes
2answers
43 views

Error in foreach loop when number range defined with a macro

I am having problems to implement a loop that runs over the months of the year and the days of each month. A simple representative example of my current approach is shown below. ...
1
vote
0answers
95 views

iterating over multiple variables with \foreach it TikZ

Note: I'm aware of another response here, but its solution was a quick-fix rather than the underlying issue. Say I want to create the following diagram but using iteration: \begin{tikzpicture} ...
2
votes
1answer
61 views

Place multiple external images in a PGFPlots axis from a PGFPlotsTable

I am trying to create an environment in which I can place several georeferenced images into a PGFPlots axis. I have working code that reads in the specified image, reads in the world file (a text ...
2
votes
1answer
37 views

Difference in behaviour using one input file and many input files

I have noticed difference in behaviour when loading a single file \input{letters/all_letters} and when loading several files using a command \newcommand*{\alphabetF}{% ...
5
votes
2answers
186 views

How to incrementally shorten lines generated by TikZ's `foreach` command?

I'm trying to draw a picture of an initial segment of the cumulative hierarchy of set theory. I generated the following MWE: \documentclass{article} \usepackage{tikz} \begin{document} ...
1
vote
0answers
62 views

How to iterate foreach with two variables and a list of values

Iteration with foreach brings error in the moment I use a list with two variables as you can see in the mwe. Is there a solution possible? As the output PDF shows the error occurs when trying to use a ...
1
vote
1answer
70 views

Using \foreach for repeated structure [duplicate]

documentclass[border={5mm}]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[scale=1, default rectangle/.style={rectangle, draw=black,thin, minimum size=1cm}, ] ...
6
votes
1answer
442 views

Repeating the same column type

I'm using package numprint to create a table which automatically formats its columns. However, the table has many columns. Right now, my table definition looks like this: \begin{tabular}{l n{2}{3} ...
2
votes
1answer
32 views

Problem displaying figure captions from array while looping

I'm attempting to generate multiple Figures using the code below. However, I'm having a problem with \caption{\questions(\plotNum)}. The error I receive is Incomplete \iffalse; all text was ignored ...
2
votes
2answers
119 views

How to check for more elements a foreach loop?

I want to check if there are more elements in a foreach loop. How can this be done? This is an example for loop: \foreach \p/\q in {a/{1,2,3}, b/{4,5,6}} \foreach \r in \q { (\r) } EDIT#1 An ...
5
votes
1answer
88 views

How can I use \foreach in math environments?

I'm looking for a way to generate in a loop the rows of an align environment, or IEEEeqnarray or some such thing. I can see that \foreach works in math mode (inside \[ \] e.g.), but something like ...
4
votes
1answer
90 views

Changing color in foreach using arrayjob

I am trying to change the color within a foreach statement. Here a way is described how to do it depending on the foreach variable. However, I want to use HTML color code, so I decided to use ...
2
votes
1answer
103 views

tikz foreach loop with two variables without using slash

So I am trying to draw the figure from this question in tikz. I have two "lists" of mathematical expressions, say x and y which have same number of elements, and I want this line to be repeated for so ...
4
votes
1answer
63 views

Code with foreach AND coordinate does not compile - but if i remove one or the other, it compiles

Based on this question i did some experiments with tikzset, coordinates and foreach. The following code plots four times the same thing. Twice with and twice without a tikzset. Twice with and twice ...
3
votes
1answer
23 views

Efficiently applying the same patch to several bibdrivers

In this answer to a question about getting Biblatex to print the ISSN field for books, I suggest a solution which uses the \xpatchbibdriver command of the xpatch package: \xpatchbibdriver{book}{% ...
9
votes
1answer
180 views

pgfmathsetmacro issue in foreach

I am trying to use \pgfmathsetmacro inside a foreach loop to connect nodes which are adjacent and named according to position as follows: \foreach \src in {0,...,\T}{ ...
2
votes
3answers
135 views

Evaluate binomial coefficient with \pgfmathtruncatemacro

How is it possible to evaluate complex formulas like \binom{2^{4}-3}{2^3} with \pgfmathtruncatemacro ? I want this to evaluate to 1287. What already works: \begin{tikzpicture} \foreach \l ...
2
votes
2answers
34 views

Lists with multiline elements to iterate with foreach

I want to have a list of elements that may contain new lines on them. For example, \def\mylist{ test, test with enter, end } However, if I try to iterate over that list with \foreach i get a ! ...
1
vote
2answers
80 views

Automated matrix padding in tikz

I encounter an error with the following code : \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning,shapes.multipart, fit,backgrounds,calc} \begin{document} \node[matrix, ...
4
votes
1answer
86 views

LaTeX foreach with non-numerical indices

I'm writing a simple script to produce randomized cards that I use to teach statistical ideas in my class. I've used Tikz to produce randomized cards that all follow the layout that I want using ...
-1
votes
1answer
66 views

How to increase the \foreach number in tikz

\foreach \z in {0,1,...,150}{ \draw [fill=black] (\z, {add(101/add(1,2*\z),-\z*\z/add(1,2*\z))}) circle (1pt);} Dimension too large.
3
votes
2answers
97 views

\foreach element of a table column

I want to code a \foreach for each element in the column Label of my.dat. Something like: \foreach \L[count=\i] in column {Label} from {my.dat} What is the right syntax? I can't find anywhere. ...
2
votes
2answers
57 views

Input a list of files

I want to include multiple files in my source. The files are to be included in a file liste.tex in the following format: fichier1.tex files2.tex test3.tex .... I relied on answering the questions ...