Stack Exchange Network

Stack Exchange network consists of 174 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.

2
votes
1answer
29 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
34 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
72 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
47 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
661 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
42 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
47 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
67 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
105 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
271 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 = ...
1
vote
1answer
39 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
151 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
44 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
826 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
48 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
31 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} \...
2
votes
2answers
21 views

Controlling space inside nodes in \foreach loop

Using the following code from the answer to this question, how to reduce the space between mu and the +/- signs and \i \documentclass{beamer} \beamertemplatenavigationsymbolsempty \usepackage{...
4
votes
3answers
122 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 ...
2
votes
2answers
37 views

modifying calculated nodes in \foreach loop

Using the following code from the answer to this question how can the nodes 0sigma be replaced by mu and how can the nodes 1sigma 2sigma 3sigma be replaced by +1sigma +2sigma +3sigma \documentclass{...
1
vote
1answer
51 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
69 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
36 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
322 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
155 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 ...
2
votes
1answer
33 views

Create checklist with pgfkeys -> multiple /.is if needed

I want to create a checklist with "static" content, but with every instance of this list I want to be able to check or uncheck some items of the list. As I want to learn PGFKeys, I tried to do it ...
2
votes
1answer
73 views

Equation with summation - regression plotting - pgfplots

I am trying to 3D plot the below equation in tikz. I have basic premise setup like this, with sample set as datatable. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.15} \...
1
vote
0answers
47 views

foreach and intersection

what's wrong with my code? The usage of the foreach loop instead of the direct draw commands leads to an error that the path is not known. Do you have any suggestions? Thanks a lot in advance! ! ...
1
vote
2answers
53 views

TikZ Loop through array of arrays

I would like to loop over an array and access each x- and y-coordinate separately, because I want to modify the coordinates before using them on a node. Currently it is only working when inserting ...
5
votes
3answers
417 views

Wrong calculation in Tikz foreach

I've a misunderstanding about the method Tikz compute some numbers. I draw a graph with some scale. Here is a MWE : \documentclass{standalone} \usepackage[french]{babel} \usepackage{tikz} \begin{...
2
votes
2answers
54 views

Latex macro lists in \foreach

I have the following code, where I define two separate lists. I want "foreach" to pick items of these two separate lists. This question is updated to make it clear that "AA" and "BB" are also needed ...
2
votes
1answer
49 views

Looping over existing colours in addplot in pgfplots

In Change color in addplot in for loop of pgfplots It was discussed how to loop over nonexistent colours in \addplot and axis I would however like to loop over existing colours, but: \documentclass[...
1
vote
1answer
54 views

TikZ-matrix: Generating a table from two nested foreach loops

For the following MWE, I would like to know how I can reduce the code by having two nested for loops. \documentclass[border=10mm]{standalone} \usepackage{tikz} \usetikzlibrary{matrix} \begin{...
5
votes
2answers
426 views

Simplifying \foreach to repeat a drawing

I use the following code to repeat a drawing. Can it be simplified? \documentclass{beamer} \setbeamertemplate{navigation symbols}{} \usepackage{tikz} \begin{document} \begin{frame}[fragile,t] \...
0
votes
1answer
70 views

LaTeX error: illegal parameter number in definition of \pgffor@b

I am trying to use a loop. The following does not work: \foreach \a in {no,has}{ \begin{table}[H] \footnotesize \captionsetup{width=.9\linewidth} \caption{text} \vspace{-22pt} ...
3
votes
1answer
38 views

The node positions in chain changed unexpectedly

As shown below, the node positions have been changed when using chain. How to fix it? \documentclass[tikz]{standalone} \usetikzlibrary{positioning, chains} \begin{document} \begin{tikzpicture}[...
8
votes
3answers
105 views

foreach path operation - confused about syntax

MWE: \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture} \draw (0:2) foreach \a in {30,60,...,330} { -- (\a:2) } -- cycle; %\draw foreach \a in {0,30,...,330} { (\a:2) -- } ...
2
votes
1answer
51 views

Loop newcommand with variable arguments

Following my previous question, I would like to know how to have variable inputs for a newcommand in order to do the following \documentclass{article} \newcommand*{\repsum}[VARIABLE NUMBER]{ \...
9
votes
4answers
513 views

Loop code for repeated sums

I tried to read other topics regarding \newcommand* to create a macros in order to have repeated summations with a single command but I was not able to understand the logic behind it. Let me explain ...
3
votes
0answers
52 views

\savebox doesn't work inside tikz foreach loop [duplicate]

I need to process listed content passed to a \foreach loop inside a tikz environment. But \savebox seems not to behave the same as outside tikz. In particular, the following code: \documentclass{...
12
votes
1answer
117 views

Smarter way for a drawing

Consider the following MWE: \documentclass[border=5pt]{article} \usepackage{tikz,anysize} \marginsize{0cm}{0cm}{0cm}{0cm} \definecolor{forest}{RGB}{34,139,34} \definecolor{rot}{RGB}{220,20,60} \...
6
votes
1answer
83 views

how to draw a gray coded disk

I can draw a coded reglet with the binary code, the Gray code or any other code from the code table. \documentclass[border=7pt,10pt]{standalone} \usepackage{tikz,ifthen} \usetikzlibrary{ ...
3
votes
1answer
35 views

Why the last element of the foreach loop is not displayed correctly

in the double foreach loop below, the last element is not displayed vertically. I do not see why? \documentclass[border=7pt,10pt]{standalone} \usepackage{tikz} \usetikzlibrary{ positioning } \begin{...
5
votes
3answers
105 views

How to compute the *key* of a pgfkeyssetvalue command?

I have a list of (angles/value) pairs. I'd like to use TikZ to draw nodes with those values at these angles (easy), then draw an edge from node i to i+1, with the value of node i as a label (not ...
5
votes
1answer
106 views

Access node anchors in tikz foreach

I want to plot some dynamical systems with tikz but when I need to iterate on the node names, there is an error because the node name is broken when I need to work on the anchors. I found multiple ...
6
votes
1answer
92 views

Visibility of path names declared in \foreach loops

Buildup Basic setting Using the intersection library, I encountered some behaviour of path names that I do not understand. The following works in the intended way: \documentclass{scrartcl} \...
1
vote
2answers
82 views

Fractions and counters in a \foreach list of pairs

I'm trying to create a macro that will take a list of pairs as an argument in order to draw a pie chart. I'm trying to make it so that portions of the pie are specified as a fraction less than 1. Here'...
5
votes
1answer
146 views

Tikz, graphdrawing: How to use \foreach variables to set edge node labels?

I wanna create and label edges using a \foreach loop to avoid having to write every single node/edge when creating large graphs. It works fine when I use it to create nodes, but when I try to label ...
7
votes
2answers
157 views

Simplify things in TikZ

How can I simplify some positioning with some foreach loops or some own styles? Here is the original picture: And here is my MWE: \documentclass[border=5pt,tikz]{standalone} \usetikzlibrary{calc} \...
6
votes
2answers
97 views

foreach-loop in align

I want to write a macro for optimisation problems and my current approach is to write a macro, that takes the target function and a list of constraints. The entries are separated by comma, and each ...
3
votes
3answers
119 views

How to store an array of values?

I need to calculate the mean of a bunch of values generated by a function inside a loop. Is it possible? \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{...