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
1
vote
1answer
48 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
57 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
16 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
28 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
23 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
37 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
40 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
48 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
37 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
97 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
53 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
38 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
127 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
273 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
21 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
80 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
121 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
66 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
71 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
261 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
172 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
59 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
22 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
60 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
139 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
26 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} ...
2
votes
1answer
67 views

How to create comma separated list as the argument of a macro or command?

In the following MWE, I tried to create a command (but I also tried with a macro) that receives #1 argument. In this case, I am trying to create a comma separated list. However, as shown in the figure ...
3
votes
1answer
273 views

How to get the index variable in the foreach loop

I have the following MWE: \documentclass{article} \usepackage{pgf, tikz} \setlength{\parskip}{0.5cm} \begin{document} \textbf{Comprehensive knowledge storage follows the evolutionary sequence given ...
1
vote
1answer
40 views

Use of plot command with a foreach loop variable

Edit: I wrote some nonsense before. Hopefully it makes more sense now. I'm trying to repeat a plot in a foreach loop with the domain of the plot shifting in each iteration. I've tried shifting the ...
2
votes
1answer
31 views

Is it possible to pass new command parameters into a foreach loop?

I am trying to generate a newcommand that will create "spinners" to teach probability to students. I have been able to produce code to generate polygon spinners with each triangular section ...
0
votes
0answers
25 views

TikZ keys in foreach loop

The following code \foreach \opt in {line width=2,dashed}{ \draw[\opt](0,0)--(1,1); }; yields the error "I do not know the key '/tikz/line width=2' and I am going to ignore it. Perhaps you ...
1
vote
2answers
46 views

Why in the TikZ code it produces two similar side by side results where shift is set 0 cm

In this code below \documentclass[10pt]{article} \usepackage{tikz} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \clip (-0.5,-0.75) rectangle (3.25,2.25); \foreach \pathname/\...
3
votes
1answer
59 views

Tikz foreach path between nodes starts at wrong position

This picture has been generated by following code. In red circles the edges start/end not on the correct side of the node. \documentclass[tikz]{standalone} % =========================================...
0
votes
0answers
52 views

add error ellipse to drawing urgent help please!

Y X angle of rotation y x h name 493285.05454 4497785.25251 161.390130 0.063687 0.057852 0.123302 FAKU 495849.34756 4495798.21639 10....
3
votes
2answers
71 views

TikZ: How to split a tikzpicture into parts with a foreach-loop?

If I have three parts of paths and nodes in a tikzpicture: what is the best way to split that up with a foreach-loop into 3 tikzpictures, where only one part is showing? Like: , , \documentclass[...
2
votes
1answer
25 views

Unexpected Behaviour in TikZ Edge Anchors with \foreach

I want to automate drawing a simple picture with TikZ using \foreach; I wrote the following code (output below): \documentclass[tikz, border=1mm]{standalone} \begin{document} \begin{tikzpicture} \...
2
votes
1answer
18 views

ForArray not working inside newcommand

I try to use the forarray package but the output is different when used inside a custom \newcommand: \documentclass{scrartcl} \usepackage{forarray} \begin{document} \newcommand{\printforarray}{% ...
0
votes
0answers
35 views

How to draw this sine function with TikZ axis [duplicate]

ok, I have a problem with drawing this, can anyone help me, I need a full code for identical graph.Thanks in advance. :(
2
votes
1answer
43 views

weird output using foreach command

So I am trying to familiarize myself with tikz \foreach command through this link Yet something strange happened. According the the linke, if I am trying to iterize two variable at the same time ...
0
votes
0answers
60 views

\foreach and \def problems

I've been trying to make a tikzpicture in 3d, using tikz-3dplot, that consists of a set of nested circular cones around the \pm z axis. There is one parameter that should control the whole thing, ...
1
vote
1answer
42 views

Phase plot better coding

So I managed to get the magnitude and phase plot as shown below: \documentclass[12pt]{article} \usepackage{tikz} \usepackage{amsmath} \usepackage{amssymb} \usepackage{pgfplots} \usepackage{float} \...
3
votes
1answer
79 views

how to generate beamer frames in a foreach loop

I need to generate several frames which each contain an image. I was thinking of looping with \ foreach but it doesn't work \foreach \nn in{1,2,...,5}{ \begin{frame}[fragile]{} \includegraphics[width=...
1
vote
1answer
40 views

Tikz setcounter not working

I have tried to emulate other code using letters instead of numbers in the foreach in tikz, so here is my code: \documentclass[12pt]{article} \usepackage{tikz} \usetikzlibrary{shapes,arrows,automata, ...
1
vote
1answer
24 views

For loop not running properly in pgfplots

In this picture, I am trying to get the dashed plots done via a loop (I managed to do so without a loop): Code: \documentclass[12pt]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \...
1
vote
2answers
42 views

Arrows drawn with \foreach point to wrong side of \node

I noticed that arrows in the below MWE point to the wrong side of the nodes if I draw them with a foreach statement, but not if I write the same drawing command manually. What is wrong? \...
0
votes
0answers
19 views

pgfplots foreach, node name is the same [duplicate]

In the mwe below, I try to have different name inside a pgfplotsinvokeforeach loop. I don't understand why the name is the same with the last value \documentclass{article} \usepackage{lmodern} \...
5
votes
2answers
205 views

Strange behaviour of foreach

I am totally dumbfounded. Consider the following code: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \a / \b in { (20:1) / (90:1) ,(-20:1) / (-90:2) ...
2
votes
8answers
110 views

defining a new command with variable name in a loop

I was trying to not write 26 redundant lines; \magic works on its own; but the loop breaks it \usepackage{pgffor,amsfonts} \newcommand{\magic}[1]{ \expandafter\newcommand\csname b#1\endcsname{\...
4
votes
2answers
125 views

I would like to create a macro to fill in a percent grid automatically in the most efficient manner

I would like to create a macro that fills in the percent grid if I call \mypercent{43}, it will fill in 43 squares. I'm doing it manually but would like help in automating the process. Here is my ...

1
2 3 4 5
13