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
1answer
30 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
29 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
35 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
65 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 <--- \...
-4
votes
0answers
502 views

Getting a million Latex (MikTex) errors

Did something drastically insane change in Latex/MikTex? I had my thesis submitted in Dec, and now I am trying to do corrections and I am getting a ginormous amount of issues/errors, some related to /...
0
votes
0answers
44 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
40 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
36 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
27 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
108 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
425 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
53 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
101 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
35 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
54 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
71 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
132 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
32 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
56 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
75 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
vote
2answers
48 views

Loop over pgfplotstable rows

I wan't to draw tikz picture based on data loaded from pgf table. Can I somehow use it like standard \foreach? \foreach \i/\j in {\mytable} \draw... What I found is \pgfplotstableforeachcolumn but ...
1
vote
1answer
51 views

Formatting of foreach-generated formulas

I'm new to Latex and have a background in software development. I find the ability of auto-generating formulas and lists impressive, but struggle to format the result properly as the letters are ...
4
votes
8answers
462 views

Get elements which are not in a list

If I have a list \def\Main{25, 76,38, 19, 58,29,88,44, 22, 11, 34, 17} that contains some number which are inside 1,2,...,25 (inclusive). How can I get a list which contains all numbers 1,2,.....
1
vote
1answer
55 views

I would like to know how to use two variables in a foreach loop

In the picture LaTeX does what I want, but only for a little bit. I would like the arrows to go all the way to the middle of the circle but decreasing in length as they go down. Here is my code. I get ...
2
votes
2answers
64 views

Why is tikz foreach behaving strange when visiting nodes

I want to use foreach to draw connections between a sequence of nodes. But, for some reason, foreach forgets the position of the last node. Here is an MWE illustrating my question: why are the two ...
0
votes
0answers
21 views

Make a list in of strings in LaTeX which can be indexed in \foreach

I have a tikz picture like so: \begin{tikzpicture} \begin{axis}[ width=0.9\linewidth, height=0.25\textheight, legend pos=north west, ymin=0, ] \foreach \yindex in {2,...,7} { ...
0
votes
0answers
8 views

pgfplotstable: create style by a loop

I used \pgfplotsinvokeforeach{0,2,4}{ \pgfplotstableset{every col no #1/.style={ column type/.add={>{\columncolor{gray}}}{} }, } to get a style for some columns. Since I need this for more complex ...
0
votes
0answers
35 views

if statement in nested foreach in tikzpicture not working - wrong syntax?

I attempt to place dots on certain grid locations by using a nested \foreach command as follows, but TeXstudio rejects the use of the second variable \y with an error 'unrecognized command'. Strangely ...
1
vote
2answers
25 views

How to get a tabbing for a foreach-loop output

Is there an easy / elementary way to get a "tabbing" here? Note, that the number of rows and columns is basically variable or depends on the loop. \documentclass[a4paper]{article} \...
1
vote
0answers
41 views

Why does this code need the tcolorbox package?

Why does this code need the tcolorbox package to compile? \documentclass[]{article} \usepackage[most]{tcolorbox} \def\Image{\includegraphics[scale=0.2]{example-image.jpg}} \begin{document} \...
0
votes
1answer
44 views

How to loop through all images (all of equal size), 2 images per page, with tikzpicture and tcolorbox on every page?

Please consider this MWE: \documentclass[a4paper, landscape]{article} \usepackage{tikz} \usetikzlibrary{calc} \usepackage[most]{tcolorbox} \newcommand\UseImage[1]{% \IfFileExists{#1.jpg}% {\...
1
vote
2answers
68 views

How to translate and rotate in TikZ in foreach loop to animate?

I'd like to animate the horizontal segment to the vertical one, rotating it around its mid point and translating it. See the gif below. I have no idea why the translation does not work as I expect. ...
1
vote
1answer
54 views

Add days to a specific date in datetime2 in a for loop / foreach loop

I want to calculate the beginning and ending date of a week (first day is Monday, last is Sunday). This is working fine for a single date. Now I want to calculate the start and end of multiple weeks ...
2
votes
1answer
115 views

How to \foreach similar commands in Tikz

So I have this : \node [above] at (\fpeval{7/16},0.04) {\tiny $\frac{7}{16}$}; \draw [color=red,latex-] (\fpeval{7/16},0) -- (\fpeval{7/16},0.2) ; \node [above] at (\fpeval{...
0
votes
1answer
71 views

Use tikzmath in between connecting coordinates with the draw function

If I understand correctly, the \draw function allows one to connect points with lines, and then (if the lines come back to the same point) fill the outlined shape. If one uses the -- ( , ) command it ...
0
votes
1answer
53 views

With Tikz & Matrix, nodes generated in a foreach loop don't accept “wind anchors” (north, south etc.)

This is a small matrix with 5x3 nodes. My true matrix is much bigger, and I preferred to give a number to each cell (from 1 to 15 - yes, I know 0 to 14 would be easier). I already numbered the cells ...
4
votes
2answers
154 views

Scaling a virtual ruler (scale) to equally-sized pictures (for multiple pictures, 360° product photography)

Imagine you have lots of slightly different images of an object like this, all taken from the same distance, with the object only rotating around its center (thus, on all pictures, the fossil will be ...
9
votes
4answers
292 views

Extract a list of distinct values from another list (remove dupes)

Suppose I have a list defined via \def\zList{0,0,1,1,1,2,2,10}. How can I obtain a (comma-separated) list 0,1,2,10 that contains the unique/distinct values in 0,0,1,1,1,2,2,10? Is there perhaps a way ...
1
vote
1answer
30 views

if statement in for each loop

I am trying to write a foreach loop where I print out one item in a list followed by a blank line. The problem is that I want to do this for every iteration after the first iteration, so that I print ...
3
votes
1answer
86 views

How to draw this function graph with plot operation(TIKZ,Loop)

I wish to draw a function graph, The analytical formula of the function is: I can use the following code to draw an image of a specific function But I want to be concise, how to define a letter n, ...
4
votes
2answers
126 views

Iterating over node names in \foreach gives \inaccessible error

I would like to connect my cylindric masses with a bold horizontal line like displayed in the following picture: The following code works fine for the first connection: \documentclass{standalone} \...
1
vote
3answers
75 views

TikZ - foreach, expansion problem, optional argument and node

I am trying to use foreach to simplify the 1st env. code in my MN(ot)WE below. There is an expansion problem regarding the optional argument in the 2nd code. Here is the output. How can I fix this ? \...
1
vote
3answers
85 views

I have some problem in this Latex program

\begin{center} \begin{tikzpicture}[x=7.5mm,y=4.34mm] % some styles \tikzset{ box/.style={ regular polygon, regular polygon sides=6, minimum size=10mm, inner sep=...
5
votes
4answers
295 views

On a conditional command: more powerful than \ifnum

According to the TEX in a Nutshell, Petr Olšák, page 16/29, we get: \ifnum ⟨number 1⟩ ⟨relation⟩ ⟨number 2⟩ . The ⟨relation⟩ could be < or = or >. It returns true if the comparison of the two ...
3
votes
3answers
367 views

\foreach and names

I am trying to write a command to draw a cycle graph with Tikz, basically a polygon. The parameters of the command are the number #1 of vertices, and the radius #2 of the figure. My initial thought ...
1
vote
1answer
66 views

for loop in frame subtitle of beamer

I would like to build multiple slides of a frame in beamer by using a for-loop to load a specific image file out of a group in each slide. Currently, I can either loop inside the frame and advance in ...
0
votes
0answers
34 views

Creating a macro for supertabulars \tablefirsthead [Beginner]

I am trying to create a macro that reads in the number of given elements and creates the table header for the supertabulars command \tablefirsthead. There is a loop for getting the size of the given ...
1
vote
2answers
62 views

A question regarding multi-variable \foreach

In TikZ & PGF Manual for Version 2.10-cvs, page 676/880 there is an example as below: \foreach \x / \y in {1/2,a/b} {``\x\ and \y''} It is supposed to yield: "1 and 2""a and b"...
2
votes
3answers
189 views

How to use foreach inside tikz fill

I am trying to draw a filled staircase shape (shown below) generated with the code below. \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{calc, math} \begin{document} \begin{tikzpicture} ...
0
votes
1answer
29 views

Table with foreachloop as writeout in a external textfile

I create a table with 2 foreach-loops. Now I would like to have that as a textfile too. But there are some if-decision. How to use newwrite correctly here? \documentclass[]{article} \usepackage{tikz} ...

1
2 3 4 5
14