{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

3
votes
1answer
52 views

Assign each drawing (line,path,etc.) as elements of a vector, so it can be recalled, used, and edited in looping

I want to know how to set drawing elements as variables(elements of a vector/array) so that it can be recalled and modified (in each loop). For example i have a line (\draw (start) -- (end)) and want ...
2
votes
1answer
46 views

Draw lines in a loop of n times

I'm trying to create a code that draw different lines in each iteration, but it does not work if when i used the loop index -> \x. Any suggestion? Thanks. \documentclass[border=10pt,tikz]{standalone}...
5
votes
1answer
77 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}; \...
3
votes
1answer
57 views

Problems using `\foreach`to parametrize a sequence of graphs in Beamer

I want to create a series of overlapping graphs in a Beamer slide, with little variations between them. I have code that works as expected in one case, but fails in other, and I don't understand why, ...
3
votes
1answer
74 views

Defining and expanding macros In loops

I want to define and expand macros in a \foreach loop. The names of the macros depend on the iteration step. The macros I define are interpreted as strings rather than sets of numbers that I actually ...
5
votes
1answer
118 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 arrayjob....
4
votes
2answers
108 views

How to make editorial table from sections

How would it be possible to make an editorial list/table? I'm not asking how to create a list or table, but if it is possible to attach something to \section's and \subsection's in the form of a \...
1
vote
0answers
78 views

pgfplots - Create multiple plots from one table (rows 0--3, 4--7,…)

Using JMH in java I have created file. Suppose .csv file looks like this (but far bigger): "Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit","Param: capacity","Param: ...
3
votes
1answer
67 views

How to draw a gradient spiral with tikz

I want to draw a gradient spiral with tikz and I am encountering problems. My current code: \draw[line width=0.24mm, rotate=120, color=red] (0,0) \foreach \i [evaluate={\r=(\i/1212)^2;}] in {0,5,......
8
votes
2answers
142 views

Using Macros within Loop

I was wondering if there is a way to use macro within a \foreach loop. For example some of my defined locals are: \newcommand{\labA}{Adult} \newcommand{\labB}{Adolescent} \newcommand{\labC}{Child} ...
2
votes
1answer
81 views

Mathematical calculation within \foreach loop in tikz

The minimal code below demonstrates the problem. The code as it is does not give the desired output. I assume the \x-\y is not being correctly handled. I have tried including braces, brackets, but to ...
2
votes
1answer
35 views

Using calc library with foreach loop over some coordinates

I am drawing a schematic diagram which contains the sun in several places. For the purpose of this example, the sun is just a circle surrounded by 12 equally spaced a's. Using the calc library \...
2
votes
1answer
57 views

Alternative to `foreach` loop to use an `edef`

I need to create some dynamic name macro and I want to create them from a coma separated list of parameter in #1 in one loop. foreach is not the solution because it forces the use of gdef and I want ...
4
votes
1answer
47 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
51 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
65 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: \documentclass[10pt,...
2
votes
2answers
41 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} \usepackage[T1]{...
0
votes
1answer
45 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} \usepackage[...
4
votes
2answers
59 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
23 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 mod(\i,13)...
2
votes
0answers
54 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} \usepackage[...
2
votes
1answer
30 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
246 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
83 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]{ \stepcounter{...
5
votes
2answers
61 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
17 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
50 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 angles,...
2
votes
0answers
16 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
68 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
42 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 &...
0
votes
1answer
191 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
324 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 work....
4
votes
3answers
184 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
105 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} \usepackage{tikz}\usetikzlibrary{calc,shapes,positioning,arrows,...
9
votes
3answers
248 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
208 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
105 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
159 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. \documentclass[margin=10pt]{...
2
votes
1answer
154 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
46 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. \documentclass{...
1
vote
0answers
125 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
63 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
38 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}{% a,aa,b,c,d,e,ee,f,g,h,i,ii,...
5
votes
2answers
192 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} \begin{...
1
vote
0answers
66 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
74 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}, ] %--------...
7
votes
1answer
531 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} n{...
2
votes
1answer
34 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
121 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
98 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 ...