Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [foreach]

{foreach} is for questions regarding the TikZ/PGF module of the same name which can also be used as a standalone package pgffor.

10
votes
3answers
189 views

Smart-expansion of a range to a list of numbers

I am wondering if there is a simple way to expand some input text such as "3-7" as "3,4,5,6,7"? For context, I am using \foreach and want to be able to write \foreach \x in {3-7, 9, 14, 52} and ...
3
votes
2answers
31 views

Passing optional arguments to \printbibliography as variables

title and keyword are optional arguments to the Biblatex command, printbibliography. Is it possible to pass a title and keyword as variables to printbibliography? The use case is the production of a ...
9
votes
1answer
215 views

Why does a perfectly-identical repetition of a drawing command given within an earlier loop 𝘯𝘰𝘵 produce exactly the same line?

Question. Why does the following code produce a line from vertex 0 to vertex 1 which does not perfectly coincide with the analogous line drawn earlier (by way of the foreach-loop)? \begin{...
0
votes
1answer
41 views

Tikz \foreach to work with the aligned environment

I am trying to use the \foreach command to create something with the same effect as: \begin{align*} 1 \\ 2 \end{align*} The following code fails to work: \begin{align*} \foreach \x in {1,2} ...
2
votes
1answer
52 views

Making a checkerboard with `foreach`

Why are these two diagrams different? \documentclass{amsart} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{tikz} \usetikzlibrary{calc,intersections} \begin{document} \begin{tikzpicture} \...
2
votes
2answers
40 views

If clause within a loop

I have a similar issue as the one discussed here If condition controlled with a loop variable. To summarize my case: when looping through a continous range of numbers, from 1 to 24, I'd like do ...
6
votes
5answers
305 views

Nested loops to process groups of pictures

The following MWE processes groups of pictures, placing them on a slide with a caption below the picture. The slides are made using the pdfscreen package, and the picture and caption placement is done ...
2
votes
1answer
28 views

Place node in the middle on an arc during a foreach statement

This question is akin to this one, The difference being that I want to place my nodes during a foreach loop. MWE: \documentclass[border=5pt,tikz]{standalone} \usepackage[utf8]{inputenc} \usepackage[...
2
votes
1answer
24 views

using two `\foreach` variables multiplied to select a color mixture

I'm trying to draw a grid with a mix of colors, that changes depending both on the x and y coordinate (MWE): \documentclass[border=4pt]{standalone} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}...
3
votes
2answers
60 views

Filling (continuous) Path using \foreach with complex calculations for each point

I am trying to draw a curve by calculating every point's position in a \foreach loop (potentially hundreds of points). Since the calculation is quite complex, I use \pgfmathsetmacro multiple times to ...
3
votes
1answer
27 views

Specifying coordinates in tikzcd arrows with a foreach loop

I'm trying to use a foreach loop to draw a whole bunch of arrows in a tikzcd environment by using the foreach loop to specify coordinates but I can't get it to compile. Here's a minimal example of ...
1
vote
1answer
76 views

Populating a tikz matrix with complex content

I am trying to populate a tikz matrix dynamically using foreach to loop over a list-argument and breaking it further apart using xstring operations. I am hitting an issue where, as far as I can tell, ...
1
vote
1answer
31 views

looping through with a function to generate coordinates for PGFPlots graph

Is there a way to loop through with a function in pgfplots to generate a set of coordinates? So far I've done the manual way of just inputting values, but this will quickly get tedious as I want to ...
1
vote
1answer
22 views

\foreach iterates through list as one argument? - Help please

My question is very simple. The following lines \documentclass[10pt,german]{article} \usepackage[T1]{fontenc} \usepackage[ngerman]{babel} \usepackage{pgffor} %foreach \expandafter\xdef\csname ...
1
vote
2answers
108 views

How to place nodes around a circle from some initial angle?

The code below generates 6 nodes placed around a circle at angles 60, 120, 180, ..., 360 with labels 1, 2, 3, ..., 6, respectively. However, I would like to place these 6 nodes in the way (where the ...
1
vote
2answers
56 views

foreach / pgfmath: create a list of specific values

I would need a list, possibly an array (for later use in a foreach loop / TikZ graphic), which contains the following values ​​(a_n) in order (n = 1,2,3, ...): 45,135,225,270,315, 45,45,90,135,135,...
6
votes
2answers
523 views

First index is not integer using foreach loop from 0

I am trying to draw a tree using tikzpicture like this: \documentclass{article} \usepackage{tikz} \usetikzlibrary{math} \begin{document} \begin{tikzpicture} \tikzstyle{node}=[circle, fill=blue!25,...
1
vote
1answer
33 views

Create command that uses a \foreach to be used in a barycentric cs

I'm trying create a command that will be used in a barycentric cs:. I will use the barycentric cs a lot of time to get a node the middle of others, so I'm trying to make it less painfull for myself. ...
0
votes
1answer
34 views

Newcommand that uncludes a foreach with unknown number of parameters

Sorry, but part of the code is in French. However, it won't matter because it's only the listed text I currently have a new command named \listerfe that, combined with \listerfenextarg and \...
3
votes
2answers
86 views

"Illegal unit of measure (pt inserted)” Problem with foreach

I'm trying to make a series of circles with gradients. On the second page, which is created, there is only /2pt/1pt/2pt and on the last /20pt. I guess there's something wrong with my foreach loop, but ...
6
votes
1answer
170 views

Using for loop in tikz to draw repeated shapes

I am trying to create a lenticular pattern like the one in the picture. I believe the repeated shape can be drawn using a for loop in tikz, but I wasn't able to get it done properly. Appreciate any ...
2
votes
1answer
48 views

Generating TikZ Nodes and Labels from Custom Array Strings

I am trying to use the TikZ environment to annotate a graphic with labels in multiple specific locations. Instead of repeating the node command many times and changing the node location and label, I ...
1
vote
1answer
41 views

Tikz, foreach, evaluate and \ifodd combination yields “Use of \@next does not match it's definition”

I'm trying to run this. \documentclass[tikz,border=5mm]{standalone} \begin{document} \begin{tikzpicture} \draw\foreach \s [evaluate=\s as \lowhigh using \s+1] in {1,...,4}{ \ifodd\...
6
votes
1answer
110 views

Breaking a Loop in Tikz

\documentclass{article} \usepackage{tikz} \begin{document} \foreach \N in {8} {\begin{tikzpicture}[scale=1.2,declare function={f(\x)=((1/3)*(\x)^(3)-3* (\x)^(2)+8*\x-3;}, lnode/...
2
votes
2answers
66 views

Why does the iterator in foreach not work?

I've split an animated GIF into the frames and saved them as a PNG sequence. I use the beamer class and want to load the images from the sequence, replacing each other without an autostart animation. ...
1
vote
1answer
47 views

Iterating through a set of polar coordinates

This plots five vertices of a pentagon: \begin{tikzpicture} \def\Verts{ {0:1}, {72:1}, {144:1}, {216:1}, 288:1 } \foreach \Vert [count=\i] in \Verts { % Draw ...
2
votes
1answer
49 views

\foreach loop for \tikzset

I have the following code for drawing circles whose different radius. As seen in code there are two different pic statement (d1 and d2). \documentclass[margin=3mm]{standalone} \usepackage{tikz,pgf} \...
2
votes
2answers
43 views

Formatting output for \newcommand with for loop

I have the following minimum example \documentclass[12pt]{article} \usepackage{pgffor} \newcommand{\formatlist}[2]{ {x^#1} \foreach \x in {#2} {,x^\x}} \begin{document} $$\formatlist{5}{6,7}$$ \end{...
2
votes
2answers
81 views

Extract a sublist from a foreach list

I borrowed code from here for this question. The code was used to draw a hexagram (e.g.䷊), of which each stroke is corresponding to a binary digit from a list (e.g. {1,0,1,1,1,1}). A foreach loop ...
0
votes
0answers
52 views

Expand Tikz matrix with foreach statement?

I am playing with Tikz matrices and would like to use the foreach statement to "expand a matrix". More precisely, I wonder if I can use a foreach statement such as: \n in {Alice (the genious), Bob, ...
6
votes
7answers
761 views

Drawing concentric circles with alternating colors by means of \foreach in TikZ

I would like to draw concentric circles like these: by means of TikZ and \foreach command. The way I achieved it is very elementary (and burdensome): \documentclass[standalone] \usepackage{...
1
vote
1answer
53 views

Indexing arrays in a \foreach in tikz

The arrays \xcoordinates and \ycoordinates define points on a grid. I'm simply trying to connect all of the points sequentially with short line segments. \documentclass[12pt]{article} \usepackage{...
2
votes
1answer
56 views

Parameterize node circular sector shaded

I want to parameterize node creation in a foreach. The creation prozess was solved in: Cut part of radialshading out as node shape circular sector I think the substitution in the foreach has a ...
1
vote
1answer
104 views

tikz \foreach to iterate over a python list via pythontex

I am using pythontex to read in a large python list from disk into my .tex file; I wish to use the \foreach command from the tikz package to do some typesetting for each of the items in the list. MWE ...
4
votes
1answer
134 views

Neural networks numerical labels

The code given below generates a MWE. \documentclass{standalone} \usepackage{lmodern} \usepackage{neuralnetwork} \newcommand{\linklab}[4]{\ifnum0=#2 $w_{0}$ \else $w_{{#2}}$ \fi} \begin{document} ...
5
votes
3answers
324 views

What is wrong with the use of `isodd` of `xifthen`?

The white/black board can be drawn by testing the parity of node positions as follows: \documentclass[tikz]{standalone} \usepackage{xifthen} \begin{document} \begin{tikzpicture}[every node/.style = ...
0
votes
1answer
58 views

Using \foreach loop for negative values with decimal points

Since \foreach loop does not accept values with decimal point; I faked the placing of decimal point in the x axis. I could not accomplish that in the y axis since it uses negative values, in which ...
4
votes
2answers
236 views

Drawing Grid Lines using \foreach

I am trying to draw gridlines inside a square. Here is my code: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.15} \begin{document} \begin{figure}[ht] \centering \begin{...
1
vote
1answer
61 views

Problem with foreach in \node with rectangle split

I am attempting to automate the use rectangle split parts with a foreach loop. In the following MWE, the manual use of \nodepart works as expected. The \foreach loop fails with ./makebox-mwe.tex:71: ...
9
votes
5answers
855 views

Tikz picture using two “foreach” loops

I am making a picture using foreach. MWE is appended below \documentclass{article} \usepackage[svgnames]{xcolor} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \x in {0,...,5} ...
1
vote
1answer
58 views

modifying decimal point in calculated nodes in \foreach loop

Using the following code from the answer to this question How can the 0.10 ticks appear as 1.0 How can the x axis black ticks look like the red ones but keeping the intermediate ticks appearing ...
1
vote
1answer
80 views

Drawing lines in relation to nodes in \foreach loop

Using the following code from the answer to this question, how can the red lines be drawn from one node to another, for example from -3 to 3 positions \documentclass{beamer} \...
3
votes
2answers
34 views

Controlling space inside nodes in \foreach loop

Using the following code from the answer to this question, how can I reduce the space between \mu and the +/- signs and \i? \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{...
4
votes
3answers
131 views

TikZ call a macro between subsequent points in a list

In TikZ, I would like to build a macro \drawEdges which for a given list of points produces code that runs through all pairs of two subsequent points, and runs the \drawEdge macro for them. For ...
3
votes
2answers
48 views

modifying calculated nodes in \foreach loop

Using the following code from the answer to this question, how can the 0sigma node be replaced by \mu and how can the nodes 1sigma 2sigma 3sigma be replaced by +1sigma +2sigma +3sigma? \documentclass{...
2
votes
1answer
59 views

PGFplots: Global setting of coordinates labels

The following code results in an error when introducing the foreach part. So, I would like to know what is wrong in it. \documentclass[border=1cm]{standalone} \usepackage{pgfplots} \pgfplotsset{...
1
vote
1answer
72 views

Simplifying repetitive drawings and nodes placing

How to apply the following code, from the answer to this question (which gives the first drawing) to draw the second and third drawings \documentclass{beamer} \beamertemplatenavigationsymbolsempty \...
3
votes
1answer
39 views

Reusing of DeclarePairedDelimiter in a foreach manner

I'd like to reuse mathtools DeclarePairedDelimiter in a foreach loop manner, but I have never done any low-level (La)TeXing before. Here is my code: \documentclass{article} \usepackage{mathtools} \...
5
votes
2answers
334 views

Simplifying repetitive drawings and node placing

I use the following code to draw repetitive lines and place nodes in specific locations for later on drawing circles and connecting them with lines. Is there a simpler way to do this job, as using \...
5
votes
2answers
223 views

Arithmetic inside tikz

I'm having difficulty performing arithmetic inside tikz. I've written: \foreach \s in {6,...,8} { \node[draw,red,circle] at (0:(\s-2)cm) {$\s$}; } Somehow the arithmetic (\s-2) is not ...