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.

Filter by
Sorted by
Tagged with
2
votes
2answers
27 views

Confused with updating a newcommand constant inside a foreach loop

I am confused on how to update a "constant" construct inside a \foreach loop, the similar questions on here don't directly address the issue I am facing and I'm not experimented enough (yet! ...
0
votes
1answer
40 views

Define newcommand inside a loop

In my latex document I have defined an array of element and I am making a loop within this array. I would like to define newcommand inside this loop. The idea is to make \newcommand{\name1}{ \begin{...
2
votes
2answers
46 views

drawing curved connectors within \foreach loop in a graph

I am trying to draw a graph on 216 vertices - 215 vertices distributed on a wheel around a fulcrum. Then I want to connect all the peripheral vertices to the fulcrum and join the vertices on the wheel ...
1
vote
3answers
57 views

Apply operations to iterator \x in \foreach loop in Tikz

I am trying to draw a graph comprised of 13 triangles joined at the centre (i.e. a wheel graph with some edges missing from the outer cycle). I managed to connect the outer vertices to the central one ...
4
votes
2answers
45 views

\foreach loop doesn't work with \input

The result of this: \foreach \x in {1,2,3}{% \x } and this one are the same: \newcommand{\mycommand}{% 1,2,3% } \foreach \x in \mycommand{% \x } However if i make a "example.tex" file ...
1
vote
0answers
16 views

Create columns in beamer with foreach

I cannot manage to create columns with \foreach in beamer, the following code: \documentclass{beamer} \usepackage{pgffor} \begin{document} \def\a {0.2, 0.2, 0.2} \begin{frame} \begin{columns} ...
0
votes
2answers
47 views

\foreach coordinate names in PGFPlots

I have some points defined via \coordinate (A1) at (-4,0); \coordinate (B1) at (-2,1); \coordinate (C1) at (0,0); ... And I want to place a little dash at their location. I tied two approaches, but ...
1
vote
0answers
40 views

Tikz-matrix by loop, calculations inside

I looked here and tried to use \expandonce{\pgfmathprint{\n+1}} \expandonce{\&} Text inside the matrixcontent-loop. But this does not work. What do I have to do? \documentclass[margin=5mm, ...
0
votes
1answer
16 views

Multiple thmboxes with for each loop

I want to get rid of a lot of redundant code while defining thmxboxes. I tried to use for-each loops, but it does not work. The following code (that does not work) should give you an idea of what I'm ...
0
votes
1answer
46 views

Even odd slideshow with foreach loop in TikZ

I am trying to prepare a slideshow to illustrate the countability of the set of all integers. Here is what I have done so far: \documentclass[aspectratio=169]{beamer} \usetheme{CambridgeUS} \...
0
votes
1answer
20 views

Using \path or \url within a foreach loop

When trying to nest \url or \path within a for-each loop (not to be confused with TikZ paths), the text from the loop is not printed: MWE: \documentclass{article} \usepackage{pgffor} \usepackage[...
1
vote
1answer
35 views

Use a foreach inside an addplot to evaluate a sum

I am trying to sum several fonctions in a plot with a loop (as I am trying to make the process automatic), and foreach doesn't seem to be able to help me. Unluckily the question already asked ...
4
votes
4answers
183 views

Use a list in a foreach loop

I am trying to make a plot more automatic and I am trying to impose the presence of samples near point of interest. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \...
1
vote
1answer
41 views

Foreach loop in Latex gives error “undefined control sequence”

I checked multiple times how to write a foreach loop in Lualatex with PDF output but I simply do not get it to work. Here is a simple example with a complete document \documentclass[paper=152.4 mm:228....
2
votes
0answers
30 views

foreach in path construction behaves differently whether start is node or coordinate

In tikZ's manual, following code is proposed to illustrate usage of foreach inside a path construction command: On the image below, this is figure (1). Strangely, when the starting point ((0,0) in ...
1
vote
1answer
48 views

Overwrite node's option in TikZ

I'm using \foreach in order to simplify the task of manually setting nodes with a certain style, but I'd like to change some of the nodes' options afterwards. \documentclass{article} \usepackage{tikz} ...
8
votes
2answers
357 views

Draw Riemann Sum in two dimensions using Tikz

Anyone have ay idea how can I draw this figure using Tikz or PgfPlots? For one dimension I can bur, for two I have no idea. I would like to provide a function $z=f(x,y)$, the ranges for $x; (a\le x\...
1
vote
1answer
42 views

tikztimingtable: math in foreach

I have following code: \begin{tikztimingtable}[% timing/dslope=0.1, timing/.style={x=5ex,y=2ex}, x=5ex, timing/rowdist=3ex, timing/name/.style={font=\sffamily\scriptsize} ] CLK ...
0
votes
1answer
30 views

Can anyone help me about this graph using \foreach{}

So I need to create thig graph using equation y= 2ax^2±12x using \foreach{} for a={−2.4,−2.1,...,2.4} Thanks in advance.
1
vote
2answers
51 views

How to use \foreach with two \pgfmathsetmacro in the list

\documentclass[10pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry} \...
4
votes
3answers
139 views

Newtcolorbox and foreach

I have defined 2 Boxes: \documentclass{article} \usepackage[most]{tcolorbox} \newtcolorbox{one}{} \newtcolorbox{two}{} \begin{document} \begin{one} The new command works fine \end{one} \begin{two} ...
3
votes
1answer
62 views

PGFplots inside foreach to produce several figures

I use the foreach command to produce several figures. My code is the following: \documentclass[border=5mm,tikz]{standalone} \usepackage[portuguese]{babel} \usepackage[utf8]{inputenc} \usepackage{tikz,...
2
votes
2answers
37 views

Connect interseption points with arrows in foreach loop in pgfplots

I am looking for a way to draw arrows between each point in a sequence of points calculated in a foreach loop as intersections of vertical lines with a graph inspired from here. \documentclass[border=...
1
vote
1answer
27 views

Insert legend in a looping PGFplots

I want to intert the legend for my picture iteratively. My code is: \documentclass[11pt,border=10mm]{standalone} \usepackage[portuguese]{babel} \usepackage[utf8]{inputenc} \usepackage{tikz,pgfplots} \...
3
votes
1answer
170 views

Enhanced animation

I started with a simple animation and tried in the second step to improve it. In the second frame I included a long horizontal rectangle, filled by white squares (foreach loop). Is there a way to save ...
1
vote
2answers
35 views

Changing colors in Pgfplots using \foreach

I want to to several curves using foreach and PGFplots, but each curve witha different color. Here I present my code: \def\R{1} \begin{tikzpicture} \begin{axis}[ xmin = -1.5, xmax = 1.5, %...
1
vote
1answer
74 views

Plotting resistance and reactance curves on the Smith Chart

For my class, I have been trying to plot constant resistance and reactance curves on the Smith chart. While the latter appears to be straightforward, the only way I can think of for the former is ...
3
votes
1answer
80 views

Using foreach to make an alphabet chart?

I'm trying to make an alphabet chart similar to this one here: I've got a set of images prenamed with pic1.png, pic2.png. I've been able to get a forloop working to get a set of the images to appear ...
2
votes
1answer
58 views

How would I got about using a `\foreach` loop to draw a grid of circles with TikZ?

I have the following code \draw (3, 3) circle (0.25) node[anchor=south, above=0.2cm]{$\vec{B}$}; \filldraw (3, 3) circle (0.05); \draw (-3, 3) circle (0.25) node[anchor=south, above=0.2cm]{$\vec{B}$}; ...
0
votes
1answer
33 views

How to rotate a rectangle within a \foreach loop?

Using this code : \documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage{tikz} \begin{document} \newcounter{coreRot}\setcounter{coreRot}{45} \begin{tikzpicture}[scale=5] \foreach \x ...
4
votes
1answer
39 views

Can I change a \def inside a \foreach loop without making it visible to the whole document?

I understand that a \foreach loop creates a group and local definitions are, of course, local. Is there a way to skip just one level of the scoping? I mean I wish to make a local change inside the ...
2
votes
1answer
38 views

problems with foreach loop and intersections

I have a problem using foreach loop and intersection. My MWE looks like this: \documentclass[border=5pt,tikz]{standalone} \usepackage{pgfplots} \usepackage{tikz} \usepackage{pgfplotstable} \...
3
votes
3answers
44 views

Rectangular table with consecutive integers using foreach

I'd like to have a rectangular table with integers (like a lottery ticket), let's say 4x9, numbers from 1 to 36. I assumed that it is easy with tikz, two foreach loops. Like this: \foreach \i in {0,1,...
2
votes
1answer
47 views

TikZ \foreach loop with \csname macro list

I have a problem with a macro-defined list in a TikZ foreach loop. The macro is built by \csname...\endcsname. I've played around with multiple \expandafter or ##1 instead of #1, but with no success: ...
4
votes
2answers
75 views

Tikz edges drawn by foreach do not scale

I am using the following to create a small graph. I would like to scale the size, but the edges drawn within the foreach do not scale. \begin{tikzpicture}[scale=0.5] % problem <--- \...
0
votes
0answers
55 views

How to change the point steps?

Hey everyone i am making a cv using the altacv from marisa mayers altacv stylesheet, i change it a lot but at one point it gets difficult, i want to use float in the for each loop but i tried a lot ...
1
vote
1answer
60 views

Find several intersections between line and curve using tikz

I want to find the intersections between the orange dashed line and the blue curve using the package tikz, see the screenshot below. As can be seen, only the first intersection is shown. However, I ...
2
votes
1answer
57 views

Reuse of coordinate names in Tikz

Many times I reuse help coordinate names in tikz pictures. Normally, they are overwritten. Now I have found an instance where they are maintained. \documentclass{article} \usepackage{tikz} \begin{...
1
vote
1answer
35 views

Adressing a node in a foreach tikz chain

Connecting 2 nodes with each other is easy. I have this one cyan node connected with a round node X. Now I have a chain consisting of circle nodes and I want to connect the magenta node box with for ...
2
votes
1answer
118 views

How to use for (or foreach) instead of hardcoding

I am new to Tikz and I am trying to draw the following So far I did this manually but I was wondering how a foreach-Loop would work. \begin{document} \begin{tikzpicture}[ % \def\...
10
votes
4answers
443 views

Programmatically define macro within the body of \foreach

I am trying to write a macro \RR, allowing me to type \mathbb{R} in text, with an optional parameter for an exponent. The desired functionality is shown below: I can now write \RR\ in text. % --> ...
1
vote
1answer
56 views

Evaluate each element in a computed comma separated list

I have a permutated list which I sort, which I then use as shades for some TikZ figures. \documentclass{article} \usepackage{expl3, tikz} \ExplSyntaxOn \clist_new:N \l_my_clist \NewDocumentCommand{\...
3
votes
1answer
125 views

Evaluating a result in \foreach

I'm trying to animate total reflection.. so I need to evaluate the second angle inside the \foreach loop, I tried \pgfmathparse{asin(1.33*sin(deg(\th))}, but I got the error !missing number, treated ...
1
vote
1answer
52 views

Underscored foreach variable inside caption not working

I have the following latex code \documentclass[a4paper,11pt]{book} \usepackage{pgffor} \usepackage{graphicx} \usepackage[margin=1.25in]{geometry} \usepackage{physics} \usepackage{amsfonts} \...
3
votes
1answer
55 views

Local vs. global variables in pgf, interaction with foreach

I am trying to write a macro with variable number of inputs (this is important to me) that should return the maximum of the lengths of the different inputs. It uses the foreach macro from pgffor: \...
1
vote
2answers
79 views

Using foreach to draw a line

I desperately need some help with the following: In this MWE I would like to draw a circle (ideally: a vertical line) at an x value coming from a foreach command. \documentclass{standalone} \...
5
votes
3answers
150 views

Newcommand options and for each

I have defined a new command \case: \documentclass{article} \usepackage{pgffor} \newcommand\case[1]{ \ifx 1#1 case 1\else \ifx 2#1 case 2\else \ifx 3#1 case 3\else Illegal \fi\fi\fi } \begin{document}...
1
vote
1answer
35 views

Using a pre-defined list inside a pgfplotset style

I would like to place defined markers on certain datapoints in a plot using a predefined list of tuples \def\datalist{datapoint/mark}. I found a suitable solution of the same problem with labels which ...
2
votes
2answers
103 views

Drawing a circle graph with TIKZ with foreach placement and paths, yet the inbound for edges is off

I want to draw a circle using TIKZ and instead of manually placing the nodes and connecting the nodes I wanted to use loops as any sane person would. Now when I wrote these, the incoming edge seems to ...
2
votes
3answers
83 views

Tikz foreach does not work with \input or \directlua

When I'm trying to load data for tikz's \foreach using \input, or later with \directlua I noticed that it is not splited. \foreach \a / \n in {\directlua{tex.sprint("a/b")}} {\a} ...

1
2 3 4 5
14